You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Cloud Build连接GKE集群python未找到报错解决方法

Google Cloud Build连接GKE集群踩坑记录

初始方案与报错

最初使用gcr.io/cloud-builders/gcloud作为构建步骤镜像,执行集群凭证拉取操作,配置如下:

steps:
  - name: gcr.io/cloud-builders/gcloud
    args:
      - container
      - clusters
      - get-credentials
      - cluster-name
      - '--zone=us-central1-a' 

执行构建时触发如下报错:

Kubernetes cluster unreachable: Get "https://IP/version": error executing access token command "/builder/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=exit status 127 output= stderr=/builder/google-cloud-sdk/bin/gcloud: exec: line 192: python: not found

报错核心原因是该版本gcloud builder镜像内缺少python运行依赖,导致gcloud的凭证获取命令无法正常执行。

优化落地方案

虽然可以通过补全gcloud builder依赖、调整镜像版本的方式解决上述问题,但直接使用kubectl官方cloud-builder连接GKE集群是更简便的方案:无需手动执行凭证拉取命令,只要配置指定环境变量,kubectl会自动完成剩余认证流程。
调整后可正常运行的构建步骤配置如下:

- name: gcr.io/cloud-builders/kubectl
  env:
    - CLOUDSDK_COMPUTE_ZONE=us-central1-a
    - CLOUDSDK_CONTAINER_CLUSTER=cluster-name
    - KUBECONFIG=/workspace/.kube/config
  args:
    - cluster-info

核心配置项说明:

  • CLOUDSDK_COMPUTE_ZONE:填写目标GKE集群所在的可用区
  • CLOUDSDK_CONTAINER_CLUSTER:填写目标GKE集群的名称
  • KUBECONFIG:指定kubeconfig文件的存储路径,放在/workspace目录下可让后续构建步骤直接复用已生成的集群凭证

内容的提问来源于stack exchange,提问作者raghu_manne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.03 03:57:37