首页 > 解决方案 > 如何在 YAML 文件中指定 GKE 节点池配置,而不是使用 gcloud 容器节点池创建?

问题描述

似乎在 Google Kubernetes Engine 上创建节点池的唯一方法是使用 command 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 上的文档,在我看来,这很不完整。

标签: kubernetesgoogle-kubernetes-engine

解决方案


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

您真正需要的是一种称为“基础设施即代码”的解决方案——该代码将告诉 GCP 它想要什么样的节点池。

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

您还可以查看Google Deployment ManagerAnsible(它具有 GCP 模块,并使用 YAML 语法),它们也可以满足您的需求。


推荐阅读