gke-basics

gke-basics

热门

负责管理 GKE 集群的核心创建与资源供应、凭据获取、Autopilot 与 Standard 模式的选择以及工作负载部署。适用于创建 GKE 集群、获取 kubectl 访问凭据、配置 Workload Identity,或在 Autopilot 和 Standard 模式之间做出决策等场景。请勿用于 GKE 专项网络配置(请使用 gke-networking)、高级安全加固(请使用 gke-platform-security 或 gke-workload-security)或集群升级(请使用 gke-upgrades)。

1.6万Star
1230Fork
更新于 2026/8/5
SKILL.md
只读
名称
gke-basics
描述

负责管理 GKE 集群的核心创建与资源供应、凭据获取、Autopilot 与 Standard 模式的选择以及工作负载部署。适用于创建 GKE 集群、获取 kubectl 访问凭据、配置 Workload Identity,或在 Autopilot 和 Standard 模式之间做出决策等场景。请勿用于 GKE 专项网络配置(请使用 gke-networking)、高级安全加固(请使用 gke-platform-security 或 gke-workload-security)或集群升级(请使用 gke-upgrades)。

GKE 基础知识与关键避坑指南

Google Cloud 上的托管 Kubernetes 平台。除非明确指定需要 Standard 模式,否则默认使用 Autopilot 模式。

核心选型规则:Autopilot vs. Standard

  • 绝大多数工作负载默认优先使用 Autopilot
  • 仅在满足以下条件时使用 Standard:
    • 需要自定义节点 OS 的内核参数(sysctl)。
    • 需要自定义节点污点(taints)或特定的硬件节点池(node pool)。
    • DaemonSet 需要将宿主机操作系统文件系统的原始路径挂载为 hostPath
  • 在解释为什么需要选择 Standard 而非 Autopilot 时,请明确列出所有相符的限制条件(例如:使用了自定义 sysctl 和自定义节点污点)。
  • 如需了解高级集群架构或复杂的节点池创建规划,请参考 gke-cluster-creation

关键避坑指南与最佳实践

  1. 私有 Autopilot 集群:

    • 使用 --enable-private-nodes 指定私有节点 IP 地址。
    • 使用 --enable-private-endpoint 禁用对控制平面的公网 IP 访问。
    • 使用 --enable-master-authorized-networks--master-authorized-networks=CIDR_BLOCK 限制控制平面的访问权限:
      gcloud container clusters create-auto CLUSTER_NAME --region=REGION \
        --enable-private-nodes \
        --enable-private-endpoint \
        --enable-master-authorized-networks \
        --master-authorized-networks=CIDR_BLOCK
      
  2. Workload Identity(IAM 绑定):

    • 切勿在 Pod 中直接挂载原始的 GCP Service Account JSON 密钥文件。
    • 为 Kubernetes ServiceAccount(KSA)添加注解(annotation),将其绑定到 Google Service Account(GSA):
      metadata:
        annotations:
          iam.gke.io/gcp-service-account: GSA_NAME@PROJECT_ID.iam.gserviceaccount.com
      
  3. Autopilot 资源申请(Resource Requests):

    • 在 Autopilot 模式下,CPU 申请量必须以 250m(0.25 vCPU)为增量进行指定。如果申请了未对齐的 CPU 数量(例如 300m),会自动向上取整至最接近的 250m 倍数(即 500m / 0.5 vCPU)。
    • 资源申请量(requests)会自动等于限制量(limits)。可以省略 limits,让 Autopilot 自动设置与 requests 一致的默认值。
  4. 集群凭据获取:

    • 获取凭据时,务必明确指定 --region(针对区域级集群)或 --zone(针对可用区级集群):
      gcloud container clusters get-credentials CLUSTER_NAME --region=REGION --quiet
      

参考目录

  • 核心概念:架构、集群模式(Autopilot 与 Standard)、网络配置、弹性伸缩及安全模型。

  • CLI 使用与工具参考:工具优先级层级(MCP vs gcloud vs kubectl)、gcloud container 相关命令以及用户偏好覆盖设置。

  • 客户端 SDK:Python、Go、Node.js 和 Java 的官方 Kubernetes 及 Google Cloud Container 客户端 SDK。

  • MCP 使用指南:连接并使用 23 个结构化的 GKE MCP 工具,用于集群管理、K8s 资源操作和故障诊断。

  • 基础设施即代码 (IaC):包含 google_container_cluster (Autopilot) 的 Terraform 示例、Kubernetes Provider 资源配置及 YAML 示例。