英文:
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论