mcpField
G
gke-cluster-creation

gke-cluster-creation

github.com/google云与 DevOps21.6k6.7k 次安装今天更新
代码仓库

关于 gke-cluster-creation

指导创建 Google Kubernetes Engine 集群的参考技能,面向需要选择集群模式并定制配置的用户。默认采用 Autopilot Golden Path,并提供生产、开发测试、Standard 区域集群及 GPU/AI 工作负载模板;创建前要求确认配置。

主要功能

  1. 01引导选择 Autopilot 或 Standard
  2. 02提供多种集群配置模板
  3. 03涵盖安全、网络与自动扩缩建议
  4. 04通过操作状态跟踪创建进度

适用场景

  1. 01创建生产用 Autopilot 集群
  2. 02为定制节点需求规划 Standard 集群
  3. 03为 GPU 推理或 AI 工作负载选择模板

MCP 相关

支持通过 MCP 列出、创建和获取集群,并查询操作状态;创建前要求展示配置并获得确认。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/google/skills --skill gke-cluster-creation

安装后在 Claude Code 中输入/gke-cluster-creation确认已加载。

附带文件references/attribution.md

详细介绍

GKE 集群创建

本指南介绍如何创建 Google Kubernetes Engine(GKE)集群,提供一组最佳实践模板,并指导用户选择模式和进行自定义。所有新集群默认采用 golden path Autopilot 配置。

MCP 工具: list_clusters、create_cluster、get_cluster、 list_operations、get_operation

归属信息

必须阅读: 在执行任何 gcloud、REST API 或 MCP 命令之前,必须阅读 使用归属信息。对于直接在终端中执行的命令(切勿在生成的脚本、Terraform 或用户代码中添加),请在 gcloud 前添加前缀 CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-cluster-creation)" 并在 User-Agent 标头中追加 agent-skills/1.0 (skill:gke-cluster-creation)。

工作流

  1. 了解上下文:使用 list_clusters 查看现有集群。如果项目未知,请使用 gcloud config get-value project。
  2. 收集输入:project_id、location(区域或可用区)、 cluster_name、环境类型。如果缺少必要信息,请先询问用户,再采取行动。
  3. 选择模式并说明权衡:如果用户未指定模板或模式,请列出可用模板(例如 Autopilot、Standard Regional、GPU Inference、AI Hypercompute),并说明主要权衡(成本与可用性、Autopilot 与 Standard 节点管理)。
  4. 配置网络:自动创建子网(默认)或使用自有网络。
  5. 检查 golden path 设置:展示默认配置块 (gcloud 命令或 create_cluster JSON 负载),并在创建前与用户确认。
  6. 创建:使用 MCP create_cluster 工具或 gcloud CLI。
  7. 跟踪:使用 get_operation 监控创建进度。
  8. 验证:使用 readMask="*" 调用 get_cluster,确认已应用 golden path 设置。

模式选择

标准Autopilot(Golden Path)Standard
节点管理Google 管理自行管理
定价按 Pod 资源计费按节点(VM)计费
: : 请求 : :
节点自定义通过 ComputeClasses完全控制
DaemonSets允许(有完全控制
: : 限制) : :
GPU/TPU通过 ComputeClasses通过节点池支持
: : 支持 : :
适用场景大多数生产工作负载内核调优、自定义 OS、
: : : 需要特权的工作负载 :

规则:默认选择 Autopilot,除非客户有 Autopilot 无法满足的特定需求。

最佳实践

在指导用户或生成配置时,请遵循以下 GKE 最佳实践:

安全与网络
  1. 私有集群:默认使用私有集群(enablePrivateNodes: true),采用私有控制平面并限制公共端点(enable-master-authorized-networks),以尽量缩小攻击面。
  2. VPC 原生网络:使用 VPC 原生集群(useIpAliases: true / --enable-ip-alias),以启用别名 IP 范围和 Pod 级防火墙规则。
  3. Workload Identity:优先使用 Workload Identity(workloadPool: <PROJECT_ID>.svc.id.goog),安全地授予 GKE 工作负载访问 Google Cloud 服务的权限,而不是使用静态服务账号密钥。
  4. Shielded GKE Nodes:启用 Shielded GKE Nodes (--enable-shielded-nodes、--enable-secure-boot),以防范 rootkit 和 bootkit。
  5. 最小权限(RBAC):实施严格的基于角色的访问控制限制(scoped-rbs-bindings)。
成本优化
  1. 自动扩缩容:启用集群自动扩缩容和 Pod 水平/垂直自动扩缩容(--enable-autoscaling、--enable-vertical-pod-autoscaling),根据需求调整资源。
  2. 合理配置规格与 Spot VM:选择合适的机器类型和节点数量。对于具备容错能力的非关键批处理或推理工作负载,可考虑使用 Spot VM(--spot)。
高可用性与可靠性
  1. 区域集群:在生产环境中使用区域集群,确保控制平面在多个可用区之间复制(使用 --region 代替 --zone)。注意:标准区域集群默认会在 3 个可用区中创建节点。
  2. Pod 中断预算:建议设置 Pod 中断预算,以确保节点维护期间应用程序的稳定性。
  3. 发布渠道:订阅发布渠道(REGULAR 或 STABLE),以自动进行更安全的集群升级。

模板

1. Golden Path Autopilot(生产环境)

这是默认配置。所有设置均与 ../gke-golden-path/assets/golden-path-autopilot.yaml 匹配。

通过 gcloud:

gcloud container clusters create-auto <CLUSTER_NAME> \
  --region <REGION> \
  --project <PROJECT_ID> \
  --release-channel regular \
  --enable-private-nodes \
  --enable-master-authorized-networks \
  --enable-dns-access \
  --enable-secret-manager \
  --secret-manager-rotation-interval=120s \
  --scoped-rbs-bindings \
  --monitoring=SYSTEM,API_SERVER,SCHEDULER,CONTROLLER_MANAGER,STORAGE,POD,DEPLOYMENT,STATEFULSET,DAEMONSET,HPA,CADVISOR,KUBELET,DCGM \
  --quiet

通过 MCP(create_cluster):

{
  "parent": "projects/<PROJECT_ID>/locations/<REGION>",
  "cluster": {
    "name": "<CLUSTER_NAME>",
    "autopilot": { "enabled": true },
    "privateClusterConfig": { "enablePrivateNodes": true },
    "masterAuthorizedNetworksConfig": {
      "privateEndpointEnforcementEnabled": true
    },
    "releaseChannel": { "channel": "REGULAR" },
    "secretManagerConfig": {
      "enabled": true,
      "rotationConfig": { "enabled": true, "rotationInterval": "120s" }
    },
    "rbacBindingConfig": {
      "enableInsecureBindingSystemAuthenticated": false,
      "enableInsecureBindingSystemUnauthenticated": false
    }
  }
}
2. Autopilot 开发/测试环境

放宽部分 Golden Path 默认设置,以节省成本,并便于在非生产环境中访问。

通过 gcloud:

gcloud container clusters create-auto <CLUSTER_NAME> \
  --region <REGION> \
  --project <PROJECT_ID> \
  --release-channel rapid \
  --quiet

通过 MCP(create_cluster):

{
  "parent": "projects/<PROJECT_ID>/locations/<REGION>",
  "cluster": {
    "name": "<CLUSTER_NAME>",
    "autopilot": { "enabled": true },
    "releaseChannel": { "channel": "RAPID" }
  }
}

警告:此配置不会应用 Golden Path 安全加固措施。仅适用于开发/测试环境。

3. 标准区域集群(高可用性/自定义需求)

适用于无法使用 Autopilot 的情况(例如,需要自定义内核调优或特定节点操作系统要求)。默认会在多个可用区中创建 3 个节点。

通过 gcloud:

gcloud container clusters create <CLUSTER_NAME> \
  --region <REGION> \
  --project <PROJECT_ID> \
  --num-nodes 3 \
  --machine-type e2-standard-4 \
  --disk-type pd-balanced \
  --enable-autoscaling --min-nodes 1 --max-nodes 10 \
  --enable-shielded-nodes --enable-secure-boot \
  --workload-pool=<PROJECT_ID>.svc.id.goog \
  --enable-private-nodes \
  --enable-master-authorized-networks \
  --enable-vertical-pod-autoscaling \
  --enable-dataplane-v2 \
  --release-channel regular \
  --quiet

通过 MCP(create_cluster):

{
  "parent": "projects/<PROJECT_ID>/locations/<REGION>",
  "cluster": {
    "name": "<CLUSTER_NAME>",
    "initialNodeCount": 3,
    "nodeConfig": {
      "machineType": "e2-standard-4",
      "diskType": "pd-balanced",
      "diskSizeGb": 100,
      "oauthScopes": ["https://www.googleapis.com/auth/cloud-platform"],
      "shieldedInstanceConfig": {
        "enableSecureBoot": true,
        "enableIntegrityMonitoring": true
      },
      "workloadMetadataConfig": {
        "mode": "GKE_METADATA"
      }
    },
    "privateClusterConfig": { "enablePrivateNodes": true },
    "releaseChannel": { "channel": "REGULAR" },
    "workloadIdentityConfig": {
      "workloadPool": "<PROJECT_ID>.svc.id.goog"
    }
  }
}
4. GPU 推理与 AI 工作负载(L4/ComputeClass)

适用场景:AI/ML 推理、小型模型服务。可通过 Autopilot + ComputeClass 配置,也可使用 g2-standard-4(nvidia-l4)创建标准节点池。注意:需要具备 g2-standard-4 配额。

Autopilot ComputeClass/GIQ 方案:

# 1. Create golden path cluster (same as template 1)
gcloud container clusters create-auto <CLUSTER_NAME> \
  --region <REGION> --project <PROJECT_ID> \
  --enable-private-nodes --enable-master-authorized-networks \
  --enable-dns-access --enable-secret-manager --scoped-rbs-bindings \
  --quiet

# 2. Apply GPU ComputeClass (see gke-compute-classes.md)
kubectl apply -f gpu-compute-class.yaml

# 3. Or use GIQ for inference (see gke-inference.md)
gcloud container ai profiles manifests create \
  --model=gemma-2-9b-it --model-server=vllm --accelerator-type=nvidia-l4 --quiet > inference.yaml
kubectl apply -f inference.yaml

通过 MCP(create_cluster)配置标准节点池:

{
  "parent": "projects/<PROJECT_ID>/locations/<REGION>",
  "cluster": {
    "name": "<CLUSTER_NAME>",
    "initialNodeCount": 1,
    "nodeConfig": {
      "machineType": "g2-standard-4",
      "accelerators": [
        {
          "acceleratorCount": "1",
          "acceleratorType": "nvidia-l4"
        }
      ],
      "diskSizeGb": 100,
      "oauthScopes": ["https://www.googleapis.com/auth/cloud-platform"]
    }
  }
}
5. AI Hypercompute(A3 HighGPU/大型模型服务)

适用场景:大规模 LLM/AI 模型训练和超算推理。注意:每小时成本较高,且配额要求严格(a3-highgpu-8g/nvidia-h100-80gb-hbm3)。

通过 gcloud:

gcloud container clusters create <CLUSTER_NAME> \
  --region <REGION> \
  --project <PROJECT_ID> \
  --num-nodes 1 \
  --machine-type a3-highgpu-8g \
  --accelerator type=nvidia-h100-80gb-hbm3,count=8 \
  --disk-size 200 \
  --scopes https://www.googleapis.com/auth/cloud-platform \
  --workload-pool=<PROJECT_ID>.svc.id.goog \
  --release-channel regular \
  --quiet

通过 MCP(create_cluster):

{
  "parent": "projects/<PROJECT_ID>/locations/<REGION>",
  "cluster": {
    "name": "<CLUSTER_NAME>",
    "initialNodeCount": 1,
    "nodeConfig": {
      "machineType": "a3-highgpu-8g",
      "accelerators": [
        {
          "acceleratorCount": "8",
          "acceleratorType": "nvidia-h100-80gb-hbm3"
        }
      ],
      "diskSizeGb": 200,
      "oauthScopes": ["https://www.googleapis.com/auth/cloud-platform"]
    }
  }
}

说明

  • 如果上下文中没有 project_id,务必询问。
  • 务必询问 region(或位置)。
  • 务必询问唯一的 cluster_name。
  • 除非客户另有指定,或有自定义节点/内核/超算需求,否则默认使用 Golden Path Autopilot。
  • 如果改用 GKE Standard,务必警告用户,说明这偏离了 Golden Path,并解释由此增加的运维/管理负担(需手动管理节点池、升级和自动扩缩容)。
  • 如果用户尚未指定模板或模式,向用户介绍选项时解释其中的权衡(例如 Autopilot 与 Standard、成本与可用性)。
  • 提供配置区块(gcloud 命令或 JSON 负载),并在调用任何创建工具前请求确认。
  • 对于难以在之后更改的 Day-0 决策(网络、私有节点),发出警告。
  • 如果用户选择 GPU(g2-standard-4、a3-highgpu-8g)、TPU 或多区域/区域集群(--region 默认使用 3 个可用区),明确警告相关成本和配额要求。
  • 使用 MCP create_cluster 时,cluster.name 参数应为短名称(例如 my-cluster),而不是完整的资源路径(projects/<PROJECT_ID>/locations/<REGION>/clusters/<CLUSTER_NAME>)。parent 参数用于定义范围(projects/<PROJECT_ID>/locations/<REGION>)。

评论

支持 Markdown