关于 gcp-cloud-architect
面向 GCP 架构设计者和团队的技能,按需求推荐架构模式并评估成本,再生成 Terraform 与 gcloud 部署配置。还涵盖 CI/CD、安全审查和故障排查。
主要功能
- 01按工作负载推荐架构模式
- 02估算成本并提出节省建议
- 03生成 Terraform 和 gcloud 配置
- 04提供 CI/CD 配置指导
- 05检查安全设置与部署故障
适用场景
- 01为 SaaS 或移动后端规划 GCP 架构
- 02评估现有资源的降本机会
- 03为选定模式生成基础设施代码
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ alirezarezvani/ claude-skills --skill gcp-cloud-architect安装后在 Claude Code 中输入/gcp-cloud-architect确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/architecture_patterns.mdbest_practices.mdservice_selection.mdscripts/architecture_designer.pycost_optimizer.pydeployment_manager.py详细介绍
GCP 云架构师
为初创公司和企业设计可扩展、高性价比的 Google Cloud 架构,并提供基础设施即代码模板。
工作流程
第 1 步:收集需求
收集应用规格:
- Application type (web app, mobile backend, data pipeline, SaaS)
- Expected users and requests per second
- Budget constraints (monthly spend limit)
- Team size and GCP experience level
- Compliance requirements (GDPR, HIPAA, SOC 2)
- Availability requirements (SLA, RPO/RTO)
第 2 步:设计架构
运行架构设计器以获取模式推荐:
python scripts/architecture_designer.py --input requirements.json
示例输出:
{
"recommended_pattern": "serverless_web",
"service_stack": ["Cloud Storage", "Cloud CDN", "Cloud Run", "Firestore", "Identity Platform"],
"estimated_monthly_cost_usd": 30,
"pros": ["Low ops overhead", "Pay-per-use", "Auto-scaling", "No cold starts on Cloud Run min instances"],
"cons": ["Vendor lock-in", "Regional limitations", "Eventual consistency with Firestore"]
}
从推荐模式中选择:
- 无服务器 Web:Cloud Storage + Cloud CDN + Cloud Run + Firestore
- GKE 上的微服务:GKE Autopilot + Cloud SQL + Memorystore + Cloud Pub/Sub
- 无服务器数据管道:Pub/Sub + Dataflow + BigQuery + Looker
- ML 平台:Vertex AI + Cloud Storage + BigQuery + Cloud Functions
有关详细的模式规格,请参阅 references/architecture_patterns.md。
验证检查点: 在进入第 3 步之前,确认推荐的模式与团队的运维成熟度和合规要求相匹配。
第 3 步:估算成本
分析预估成本和优化机会:
python scripts/cost_optimizer.py --resources current_setup.json --monthly-spend 2000
示例输出:
{
"current_monthly_usd": 2000,
"recommendations": [
{ "action": "Right-size Cloud SQL db-custom-4-16384 to db-custom-2-8192", "savings_usd": 380, "priority": "high" },
{ "action": "Purchase 1-yr committed use discount for GKE nodes", "savings_usd": 290, "priority": "high" },
{ "action": "Move Cloud Storage objects >90 days to Nearline", "savings_usd": 75, "priority": "medium" }
],
"total_potential_savings_usd": 745
}
输出内容包括:
- 按服务划分的月度成本明细
- 资源规格调整建议
- 承诺使用折扣机会
- 持续使用折扣分析
- 潜在的月度节省金额
如需详细估算,请使用 GCP 定价计算器。
第 4 步:生成 IaC
为所选模式创建基础设施即代码:
python scripts/deployment_manager.py --app-name my-app --pattern serverless_web --region us-central1
示例 Terraform HCL 输出(Cloud Run + Firestore):
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}
provider "google" {
project = var.project_id
region = var.region
}
variable "project_id" {
description = "GCP project ID"
type = string
}
variable "region" {
description = "GCP region"
type = string
default = "us-central1"
}
resource "google_cloud_run_v2_service" "api" {
name = "${var.environment}-${var.app_name}-api"
location = var.region
template {
containers {
image = "gcr.io/${var.project_id}/${var.app_name}:latest"
resources {
limits = {
cpu = "1000m"
memory = "512Mi"
}
}
env {
name = "FIRESTORE_PROJECT"
value = var.project_id
}
}
scaling {
min_instance_count = 0
max_instance_count = 10
}
}
}
resource "google_firestore_database" "default" {
project = var.project_id
name = "(default)"
location_id = var.region
type = "FIRESTORE_NATIVE"
}
示例 gcloud CLI 部署:
# Deploy Cloud Run service
gcloud run deploy my-app-api \
--image gcr.io/$PROJECT_ID/my-app:latest \
--region us-central1 \
--platform managed \
--allow-unauthenticated \
--memory 512Mi \
--cpu 1 \
--min-instances 0 \
--max-instances 10
# Create Firestore database
gcloud firestore databases create --location=us-central1
包括 Cloud CDN、Identity Platform、IAM 和 Cloud Monitoring 在内的完整模板由
deployment_manager.py生成,也可在references/architecture_patterns.md中找到。
第 5 步:配置 CI/CD
使用 Cloud Build 或 GitHub Actions 设置自动化部署:
# cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/my-app:$COMMIT_SHA', '.']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/my-app:$COMMIT_SHA']
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args:
- 'run'
- 'deploy'
- 'my-app-api'
- '--image=gcr.io/$PROJECT_ID/my-app:$COMMIT_SHA'
- '--region=us-central1'
- '--platform=managed'
images:
- 'gcr.io/$PROJECT_ID/my-app:$COMMIT_SHA'
# Connect repo and create trigger
gcloud builds triggers create github \
--repo-name=my-app \
--repo-owner=my-org \
--branch-pattern="^main$" \
--build-config=cloudbuild.yaml
第 6 步:安全审查
验证安全配置:
# Review IAM bindings
gcloud projects get-iam-policy $PROJECT_ID --format=json
# Check service account permissions
gcloud iam service-accounts list --project=$PROJECT_ID
# Verify VPC Service Controls (if applicable)
gcloud access-context-manager perimeters list --policy=$POLICY_ID
安全检查清单:
- IAM 角色遵循最小权限原则(优先使用预定义角色而非基本角色)
- 服务账号为 GKE 使用 Workload Identity
- 为敏感 API 配置 VPC Service Controls
- 使用 Cloud KMS 加密密钥实现客户管理的加密
- 为所有管理活动启用 Cloud Audit Logs
- 组织策略限制公共访问
- 所有凭据均使用 Secret Manager 管理
如果部署失败:
- 检查失败原因:
gcloud run services describe my-app-api --region us-central1 gcloud logging read "resource.type=cloud_run_revision" --limit=20 - 查看 Cloud Logging 中的应用错误。
- 修复配置或容器镜像。
- 重新部署:
gcloud run deploy my-app-api --image gcr.io/$PROJECT_ID/my-app:latest --region us-central1
常见失败原因:
- IAM 权限错误 -- 验证服务账号角色和
--allow-unauthenticated标志 - 超出配额 -- 通过 IAM & Admin > Quotas 申请提高配额
- 容器启动失败 -- 检查容器日志和健康检查配置
- 区域未启用 -- 使用
gcloud services enable启用所需 API
工具
architecture_designer.py
根据工作负载需求推荐 GCP 服务。
python scripts/architecture_designer.py --input requirements.json --output design.json
输入: 包含应用类型、规模、预算、合规需求的 JSON 输出: 推荐模式、服务栈、成本估算、优缺点
cost_optimizer.py
分析 GCP 资源以发现节省成本的机会。
python scripts/cost_optimizer.py --resources inventory.json --monthly-spend 5000
输出: 以下方面的建议:
- 移除闲置资源
- 机器类型规格调整
- 承诺使用折扣
- 存储类别转换
- 网络出口优化
deployment_manager.py
生成 gcloud CLI 部署脚本和 Terraform 配置。
python scripts/deployment_manager.py --app-name my-app --pattern serverless_web --region us-central1
输出: 可用于生产环境的部署脚本,包括:
- Cloud Run 或 GKE 部署
- Firestore 或 Cloud SQL 设置
- Identity Platform 配置
- 遵循最小权限原则的 IAM 角色
- Cloud Monitoring 和 Logging
快速开始
Cloud Run 上的 Web 应用(每月低于 100 美元)
Ask: "Design a serverless web backend for a mobile app with 1000 users"
Result:
- Cloud Run for API (auto-scaling, no cold start with min instances)
- Firestore for data (pay-per-operation)
- Identity Platform for authentication
- Cloud Storage + Cloud CDN for static assets
- Estimated: $15-40/month
GKE 上的微服务(每月 500-2000 美元)
Ask: "Design a scalable architecture for a SaaS platform with 50k users"
Result:
- GKE Autopilot for containerized workloads
- Cloud SQL (PostgreSQL) with read replicas
- Memorystore (Redis) for session caching
- Cloud CDN for global delivery
- Cloud Build for CI/CD
- Multi-zone deployment
无服务器数据管道
Ask: "Design a real-time analytics pipeline for event data"
Result:
- Pub/Sub for event ingestion
- Dataflow (Apache Beam) for stream processing
- BigQuery for analytics and warehousing
- Looker for dashboards
- Cloud Functions for lightweight transforms
ML 平台
Ask: "Design a machine learning platform for model training and serving"
Result:
- Vertex AI for training and prediction
- Cloud Storage for datasets and model artifacts
- BigQuery for feature store
- Cloud Functions for preprocessing triggers
- Cloud Monitoring for model drift detection
输入要求
请提供以下信息以便进行架构设计:
| 要求 | 说明 | 示例 |
|---|---|---|
| 应用类型 | 你正在构建的内容 | SaaS 平台、移动端后端 |
| 预期规模 | 用户数、每秒请求数 | 1 万用户、100 RPS |
| 预算 | 每月 GCP 限额 | 每月最高 500 美元 |
| 团队情况 | 人数、GCP 使用经验 | 3 名开发者、中级水平 |
| 合规要求 | 监管需求 | HIPAA、GDPR、SOC 2 |
| 可用性 | 正常运行时间要求 | 99.9% SLA、1 小时 RPO |
JSON 格式:
{
"application_type": "saas_platform",
"expected_users": 10000,
"requests_per_second": 100,
"budget_monthly_usd": 500,
"team_size": 3,
"gcp_experience": "intermediate",
"compliance": ["SOC2"],
"availability_sla": "99.9%"
}
输出格式
架构设计
- 附带理由的模式推荐
- 服务栈示意图(ASCII)
- 月度成本估算及权衡分析
IaC 模板
- Terraform HCL:可用于生产环境的 Google provider 配置
- gcloud CLI:脚本化部署命令
- Cloud Build YAML:CI/CD 流水线定义
成本分析
- 当前支出明细及优化建议
- 优先级行动清单(高/中/低)及实施检查清单
反模式
| 反模式 | 失败原因 | 更好的做法 |
|---|---|---|
| 生产环境使用默认 VPC | 缺乏隔离,防火墙规则共享 | 创建带私有子网的自定义 VPC |
| GKE 节点池过度配置 | 闲置资源造成成本浪费 | 使用 GKE Autopilot 或集群自动扩缩容器 |
| 将密钥存储在环境变量中 | 在 Cloud Console 和日志中可见 | 结合 Workload Identity 使用 Secret Manager |
| 忽略持续使用折扣 | 错失 20%–30% 的自动节省 | 为稳定的基线负载合理配置 VM 规格 |
| SaaS 采用单区域部署 | 单一区域故障 = 全面停机 | 使用 Cloud Load Balancing 实现多区域部署 |
| 重负载场景使用 BigQuery 按需计费 | 规模化后成本难以预测 | 对稳定工作负载使用 BigQuery slots(固定费率) |
| 使用 Cloud Functions 运行长时任务 | 9 分钟超时,存在冷启动 | 对超过 60 秒的任务使用 Cloud Run |
交叉引用
| 技能 | 关系 |
|---|---|
engineering-team/aws-solution-architect | AWS 对应版本,同样的 6 步工作流,服务不同 |
engineering-team/azure-cloud-architect | Azure 对应版本,与前两者组成云架构三件套 |
engineering-team/senior-devops | 覆盖范围更广的 DevOps,包括流水线、监控和容器化 |
engineering/terraform-patterns | IaC 实现,用于面向 GCP 的 Terraform 模块 |
engineering/ci-cd-pipeline-builder | 流水线构建,自动化 Cloud Build 和部署 |
参考文档
| 文档 | 内容 |
|---|---|
references/architecture_patterns.md | 6 种模式:无服务器、GKE 微服务、三层架构、数据管道、ML 平台、多区域 |
references/service_selection.md | 计算、数据库、存储、消息传递的决策矩阵 |
references/best_practices.md | 命名、标签、IAM、网络、监控、灾难恢复 |