带Terraform的GKE-设置autoscaling_profile

问题描述

我在我的GKE群集上存在按比例缩小的问题,并且发现可以使用正确的配置来解决此问题。

作为地形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
    }
  }
}

但是我遇到了这个错误

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

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

我不明白吗?

解决方法

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的使用的免责声明:

如果省略了提供程序字段,则默认情况下,即使您仅定义了google-beta提供程序块,Terraform也会隐式使用google提供程序。


在整个说明中,您的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