云构建部署到 gke 集群

时间:2021-01-08 17:58:54

标签: google-kubernetes-engine kubectl google-cloud-build

我正在使用 Google CLoud Build 将图像从 Cloud repository 部署到 GKE CLuster

我试图在 cloudbuild.yaml 中添加的命令如下

 kubectl run hello-app --image='gcr.io/<project>/hello-app'

为此,我在 cloudbuild.yaml 文件中添加了以下条目

 steps:
 - name: 'gcr.io/cloud-builders/kubectl'
   args: ['run','build-image','image=my-container=gcr.io/<project>/hello-app']
   env:
   - 'CLOUDSDK_COMPUTE_ZONE=europe-west4-a'
   - 'CLOUDSDK_CONTAINER_CLUSTER=cluster-111-poc'

但它因以下错误而失败

 Running: gcloud container clusters get-credentials --project="<project>" --zone="europe-west4-a" "cluster-111-poc"
 Fetching cluster endpoint and auth data.
 kubeconfig entry generated for cluster-111-poc.
 .....
 ....
 BUILD
 Starting Step #0
 Step #0: Already have image (with digest): gcr.io/cloud-builders/kubectl
 Step #0:   No cluster is set. To set the cluster (and the region/zone where it is found), set the environment variables
 Step #0:   CLOUDSDK_COMPUTE_REGION=<cluster region> (regional clusters)
 Step #0:   CLOUDSDK_COMPUTE_ZONE=<cluster zone>
 Step #0:   CLOUDSDK_CONTAINER_CLUSTER=<cluster name>
 Step #0:
 Step #0:   Optionally, you can specify the kubectl version via KUBECTL_VERSION,    taking one of the following values: 1.14 1.15 1.16 1.17 1.18
 Finished Step #0
 ERROR
 ERROR: build step 0 "gcr.io/cloud-builders/kubectl" failed: step exited with non-zero status: 1

  ERROR: (gcloud.builds.submit) build 3eec2f29-ba4e-4b0e-82cb-16f90f43fbd4 completed with status "FAILURE"

但我已经在 cluster name 文件中输入了 zonecloudbuild.yaml

下面是集群信息

 $ gcloud container clusters list
 NAME       LOCATION        MASTER_VERSION    MASTER_IP     MACHINE_TYPE  NODE_VERSION      NUM_NODES  STATUS
 cluster-111-poc  europe-west4-a  1.16.15-gke.4901  X.X.X.142  e2-medium     1.16.15-gke.4901  3          RUNNING
  

请推荐

1 个答案:

答案 0 :(得分:0)

需要设置CLUSTER_NAME、COMPUTE_ZONE、PROJECT_NAME等环境

CLOUDSDK_COMPUTE_REGION= CLOUDSDK_COMPUTE_ZONE= CLOUDSDK_CONTAINER_CLUSTER=