【问题标题】:GKE w/ Terraform - set autoscaling_profileGKE w/ Terraform - 设置 autoscaling_profile
【发布时间】:2020-12-19 18:29:48
【问题描述】:

我的 GKE 集群存在缩减问题,发现通过正确的配置我可以解决这个问题。

作为 terraform documentation 我可以使用参数 autoscaling_profile 并将其设置为 OPTIMIZE_UTILIZATION

像这样:

resource "google_container_cluster" "k8s_cluster" {
  
[...]
  
  cluster_autoscaling {
    enabled = true
    autoscaling_profile = "OPTIMIZE_UTILIZATION"
    resource_limits {
      resource_type = "cpu"
      minimum = 1
      maximum = 4
    }
    resource_limits {
      resource_type = "memory"
      minimum = 4
      maximum = 16
    }
  }
}

但是我收到了这个错误:

错误:modules/gke/main.tf 第 70 行,资源“google_container_cluster”“k8s_cluster”中的参数不受支持: 70: autoscaling_profile = "OPTIMIZE_UTILIZATION"

此处不应使用名为“autoscaling_profile”的参数。

我不明白?

【问题讨论】:

    标签: terraform google-kubernetes-engine


    【解决方案1】:

    TL;DR

    将以下参数添加到您的资源定义中(在顶部):

    • provider = google-beta

    更多解释:

    autoscaling_profile 如文档所示是一个beta 功能。这意味着它需要使用不同的提供者:google-beta

    您可以通过以下官方文档了解更多信息:

    关注上述文档中最重要的部分:

    使用方法:

    要使用 google-beta 提供程序,只需在要使用 google-beta 的每个资源上设置提供程序字段。

    resource "google_compute_instance" "beta-instance" {
     provider = google-beta
     # ...
    }
    

    关于googlegoogle-beta使用的免责声明:

    如果 provider 字段被省略,Terraform 将默认隐式使用 google provider 即使您只定义了一个 google-beta 提供程序块


    在整个解释中添加您的 GKE 集群定义应该如下所示:

    resource "google_container_cluster" "k8s_cluster" {
      
    [...]
    
      provider = google-beta # <- HERE IT IS
      
      cluster_autoscaling {
        enabled = true
        autoscaling_profile = "OPTIMIZE_UTILIZATION"
        resource_limits {
          resource_type = "cpu"
          minimum = 1
          maximum = 4
        }
        resource_limits {
          resource_type = "memory"
          minimum = 4
          maximum = 16
        }
      }
    }
    

    您还需要运行:

    • $ terraform init

    【讨论】:

      猜你喜欢
      • 2021-12-12
      • 2021-12-14
      • 1970-01-01
      • 2021-09-02
      • 2021-10-27
      • 2021-10-24
      • 1970-01-01
      • 2019-06-29
      • 2021-05-01
      相关资源
      最近更新 更多