Kubectl 通过 Terraform 的本地执行对 GKE 集群?



我正在尝试在GKE集群中的两个节点池之间自动迁移工作负载。我在GitLab管道中运行Terraform。当创建新的节点池时,运行local-exec,并且我想封锁并排出旧节点,以便在新节点上重新调度pod。我使用这个registry.gitlab.com/gitlab-org/terraform-images/releases/1.1:v0.43.0图像为我的Gitlab工作。此外,python3安装了apk add以及gcloud cli -下载tar并使用gcloud二进制可执行文件从google-cloud-sdk/bin目录。我能够使用像./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file=<key here>.

这样的命令问题是我不能对我的集群使用kubectl。

虽然我已经在CI作业中安装了gke-gcloud-auth-plugin,第二次在HCL代码中的local-exec脚本中安装了./google-cloud-sdk/bin/gcloud components install gke-gcloud-auth-plugin --quiet,但我得到以下错误:

module.create_gke_app_cluster.null_resource.node_pool_provisioner (local-exec): E0112 16:52:04.854219 259 memcache.go:238] couldn't get current server API group list: Get "https://<IP>/api?timeout=32s": getting credentials: exec: executable <hidden>/google-cloud-sdk/bin/gke-gcloud-auth-plugin failed with exit code 1

290module.create_gke_app_cluster.null_resource.node_pool_provisioner (local-exec): Unable to connect to the server: getting credentials: exec: executable <hidden>/google-cloud-sdk/bin/gke-gcloud-auth-plugin failed with exit code 1

当我用gke-gcloud-auth-plugin --version检查gke-gcloud-auth-plugin的版本时我得到以下错误:174/bin/sh: eval: line 253: gke-gcloud-auth-plugin: not found这显然意味着没有安装插件。

我使用的图像是基于alpine的,不幸的是,没有办法通过包管理器安装插件。

编辑:gcloud components list显示gke-gcloud-auth-plugin已经安装。

解决方案是使用google/cloud-sdk image,其中我已经安装了terraform,并将此图像用于所讨论的工作。

最新更新