【问题标题】:How to Properly Change a Google Kubernetes Engine Node Pool Using Terraform?如何使用 Terraform 正确更改 Google Kubernetes Engine 节点池?
【发布时间】:2021-10-29 10:56:23
【问题描述】:

我已在 Google Cloud Platform (GCP) 项目 ($GCP_PROJECT_NAME) 中成功创建了 Google Kubernetes Engine (GKE) 集群 ($GKE_CLUSTER_NAME):

gcloud container clusters list \
--format="value(name)" \
--project=$GCP_PROJECT_NAME

#=>

. . .
$GKE_CLUSTER_NAME
. . .

使用节点池$GKE_NODE_POOL:

gcloud container node-pools list \
--cluster=$GKE_CLUSTER_NAME \
--format="value(name)" \
--zone=$GKE_CLUSTER_ZONE

#=>

$GKE_NODE_POOL

我正在检查这个配置。使用 Terraform 使用以下container_node_pool.tf 进入 SCM:

resource "google_container_node_pool" ". . ." {
  autoscaling {
    max_node_count = "3"
    min_node_count = "3"
  }

  . . .

  initial_node_count = "3"

  . . .

}

我确认上面的 Terraform 配置与当前在 $GKE_CLUSTER_NAME$GCP_PROJECT_NAME 内部运行的 $GKE_NODE_POOL 匹配:

terraform plan

#=>

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

如果我想更改$GKE_NODE_POOL

resource "google_container_node_pool" ". . ." {
  autoscaling {
    max_node_count = "4"
    min_node_count = "4"
  }

  . . .

  initial_node_count = "4"

  . . .

}

并将$GKE_NODE_POOLnodes 的数量从3 缩放到4,我在尝试plan 时得到以下输出:

terraform plan

#=>

. . .

Plan: 1 to add, 0 to change, 1 to destroy.

. . .

如何在不破坏然后重新创建资源的情况下更新$GKE_NODE_POOL

【问题讨论】:

    标签: google-cloud-platform terraform google-kubernetes-engine terraform-provider-gcp infrastructure-as-code


    【解决方案1】:

    为任何google_container_node_pool 更改initial_node_count 参数触发破坏和重新创建。只是不要修改initial_node_count,您应该能够修改$GKE_NODE_POOL 参数,例如min_node_countmax_node_count

    plan 命令的输出应该明确地向您显示哪个参数会导致破坏和重新生成行为 [红色]:

    terraform plan
    
    . . .
    
    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
    -/+ destroy and then create replacement
    
    Terraform will perform the following actions:
    
      # google_container_node_pool.$GKE_NODE_POOL must be replaced
    -/+ resource "google_container_node_pool" ". . ." {
    
    . . .
    
          ~ initial_node_count  = 3 -> 4 # forces replacement
    
    . . .
    
    Plan: 1 to add, 0 to change, 1 to destroy.
    
    . . .
    

    initial_node_count 参数似乎是导致此行为的google_container_node_pool唯一 参数; initial_node_count 参数似乎也是可选的

    你可以在官方文档here阅读这个警告。

    【讨论】:

    • 这真的是唯一的方法吗?那么 google cli 或 GUI 是在不停机的情况下调整固定大小节点池大小的唯一方法吗?
    • 您好! ? 我的问答解决了 Google Cloud REST API 和 Terraform 之间的交互仅限;更具体地说,与initial_node_count 参数相关的问题会阻止更改节点池并强制替换。如果您使用 Terraform (google_container_node_pool) 管理固定大小的节点池,您应该能够使用 node_count 参数(更多 here无需强制替代品。
    猜你喜欢
    • 2021-09-22
    • 2018-08-02
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 2021-11-22
    • 2018-02-10
    • 2021-06-07
    相关资源
    最近更新 更多