使用Terraform创建GKE集群。

huangapple go评论63阅读模式
英文:

creation of a gke cluster using terraform

问题

我正在使用以下 Terraform 代码块来创建一个 GKE 集群:

resource "google_container_cluster" "my-cluster" {
  name     = "my-cluster"
  location = var.zone

  remove_default_node_pool = true
}

resource "google_container_node_pool" "default" {
  name       = "default"
  cluster    = google_container_cluster.my-cluster.name
  location   = google_container_cluster.my-cluster.location
  node_count = 1
}

对应的 gcloud 命令如下:

gcloud container clusters create my-cluster --num-nodes=1 --zone=europe-west2-b

当我执行 terraform plan 时,没有显示任何错误:

+ location                    = "europe-west2-b"
      + managed_instance_group_urls = (known after apply)
      + max_pods_per_node           = (known after apply)
      + name                        = "default"
      + name_prefix                 = (known after apply)
      + node_count                  = 1

然而,在执行 terraform apply 时,出现了以下错误,指责节点计数。但在计划输出中,node_count 显示为 1。

│ Error: googleapi: Error 400: Cluster.initial_node_count must be greater than zero.
│ Details:
│ [
│   ***
│     "@type": "type.googleapis.com/google.rpc.RequestInfo",
│     "requestId": "0xc636f1e1fe8d9937"
│   ***
│ ]
│ , badRequest

请确保在 Terraform 代码中的 node_count 设置正确,并且不要忘记执行 terraform apply 前检查您的 GKE 集群配置,确保节点计数大于零。如果问题仍然存在,请查看 GKE 集群的其他配置,可能还有其他因素导致此错误。

英文:

Hi I am using the below terraform block to create a gke cluster

resource "google_container_cluster" "my-cluster" {
  name     = "my-cluster"
  location = var.zone

  remove_default_node_pool = true
}

resource "google_container_node_pool" "default" {
  name       = "default"
  cluster    = google_container_cluster.my-cluster.name
  location   = google_container_cluster.my-cluster.location
  node_count = 1
}

the gcloud command for this

gcloud container clusters create my-cluster --num-nodes=1 --zone=europe-west2-b

when i execute the terraform plan it is not showing any error

+ location                    = "europe-west2-b"
      + managed_instance_group_urls = (known after apply)
      + max_pods_per_node           = (known after apply)
      + name                        = "default"
      + name_prefix                 = (known after apply)
      + node_count                  = 1

However during terraform apply it fails with the below error complaining on the node count. However in the plan output the node_count is shown as 1.

│ Error: googleapi: Error 400: Cluster.initial_node_count must be greater than zero.
│ Details:
│ [
│   ***
│     "@type": "type.googleapis.com/google.rpc.RequestInfo",
│     "requestId": "0xc636f1e1fe8d9937"
│   ***
│ ]
│ , badRequest

答案1

得分: 0

尽管您正在删除默认节点池,但仍然需要创建至少1个节点(然后当然会被删除)。

resource "google_container_cluster" "my-cluster" {
  name     = "my-cluster"
  location = var.zone

  remove_default_node_pool = true
  initial_node_count       = 1
}

resource "google_container_node_pool" "default" {
  name       = "default"
  cluster    = google_container_cluster.my-cluster.name
  location   = google_container_cluster.my-cluster.location
  node_count = 1
}
英文:

Even though you are deleting the default node pool, it still needs to be created with at least 1 node (and then of course is it deleted).

resource "google_container_cluster" "my-cluster" {
  name     = "my-cluster"
  location = var.zone

  remove_default_node_pool = true
  initial_node_count       = 1
  
}

resource "google_container_node_pool" "default" {
  name       = "default"
  cluster    = google_container_cluster.my-cluster.name
  location   = google_container_cluster.my-cluster.location
  node_count = 1
}

huangapple
  • 本文由 发表于 2023年6月18日 23:53:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76501374.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定