如何在 YAML 文件中指定 GKE 节点池配置,而不是使用 gcloud 容器节点池创建



似乎在Google Kubernetes Engine上创建节点池的唯一方法是使用命令gcloud container node-pools create。我想将所有配置都放在 YAML 文件中。我尝试的是以下内容:

apiVersion: v1
kind: NodeConfig
metadata:
  annotations:
    cloud.google.com/gke-nodepool: ares-pool
spec:
  diskSizeGb: 30
  diskType: pd-standard
  imageType: COS
  machineType: n1-standard-1
  metadata:
    disable-legacy-endpoints: 'true'
  oauthScopes:
  - https://www.googleapis.com/auth/devstorage.read_only
  - https://www.googleapis.com/auth/logging.write
  - https://www.googleapis.com/auth/monitoring
  - https://www.googleapis.com/auth/service.management.readonly
  - https://www.googleapis.com/auth/servicecontrol
  - https://www.googleapis.com/auth/trace.append
  serviceAccount: default

kubectl apply失败了:

error: unable to recognize "ares-pool.yaml": no matches for kind "NodeConfig" in version "v1"

令我惊讶的是,谷歌几乎没有为我的所有搜索产生任何相关结果。我找到的唯一文档是Google Cloud上的文档,在我看来这是非常不完整的。

节点池不是 Kubernetes 对象,它们是 Google Cloud API 的一部分。因此,Kubernetes 不知道它们,kubectl 应用程序将不起作用。

您实际需要的是一个名为"基础设施即代码">的解决方案 - 该代码将告诉 GCP 它想要什么样的节点池。

如果您并不严格需要 YAML,则可以查看处理此用例的 Terraform。请参阅:https://terraform.io/docs/providers/google/r/container_node_pool.html

您还可以查看Google部署管理器Ansible(它具有GCP模块,并使用YAML语法(,它们也可以满足您的需求。

我不知道

它是否准确地回答了你的需求,但如果你想用 Kubernetes 做 IAC,你可以使用 Crossplane CRD。如果您已经有一个正在运行的集群,则只需安装其 helm 图表,就可以通过以下方式预置集群:

apiVersion: container.gcp.crossplane.io/v1beta1
kind: GKECluster
metadata:
  name: gke-crossplane-cluster
spec:
  forProvider:
    initialClusterVersion: "1.19"
    network: "projects/development-labs/global/networks/opsnet"
    subnetwork: "projects/development-labs/regions/us-central1/subnetworks/opsnet"
    ipAllocationPolicy:
      useIpAliases: true
    defaultMaxPodsConstraint:
      maxPodsPerNode: 110

然后,您可以按如下方式定义关联的节点池:

apiVersion: container.gcp.crossplane.io/v1alpha1
kind: NodePool
metadata:
  name: gke-crossplane-np
spec:
  forProvider:
    autoscaling:
      autoprovisioned: false
      enabled: true
      maxNodeCount: 2
      minNodeCount: 1  
    clusterRef:
      name: gke-crossplane-cluster
    config:
      diskSizeGb: 100
      # diskType: pd-ssd
      imageType: cos_containerd
      labels:
        test-label: crossplane-created
      machineType: n1-standard-4
      oauthScopes:
        - "https://www.googleapis.com/auth/devstorage.read_only"
        - "https://www.googleapis.com/auth/logging.write"
        - "https://www.googleapis.com/auth/monitoring"
        - "https://www.googleapis.com/auth/servicecontrol"
        - "https://www.googleapis.com/auth/service.management.readonly"
        - "https://www.googleapis.com/auth/trace.append"
    initialNodeCount: 2
    locations:
      - us-central1-a
    management:
      autoRepair: true
      autoUpgrade: true

如果需要,可以在此处找到使用 Crossplane 进行 GKE 预配的完整示例。

最新更新