Zama Ques
Zama Ques

Reputation: 1534

cloud build deploy into gke cluster

I am using Google CLoud Build to deploy an image from Cloud repository into a GKE CLuster

The command that i am trying to add in cloudbuild.yaml is as follows

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

For that I added below entry in cloudbuild.yaml file

 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'

But it is failing with below error

 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"

But I already have entered the cluster name and zone in cloudbuild.yaml file

Below is the cluster info

 $ 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
  

Please suggest

Upvotes: 1

Views: 1481

Answers (1)

Alioua
Alioua

Reputation: 1776

You need to set the environment such as CLUSTER_NAME, COMPUTE_ZONE, PROJECT_NAME

CLOUDSDK_COMPUTE_REGION= CLOUDSDK_COMPUTE_ZONE= CLOUDSDK_CONTAINER_CLUSTER=

Upvotes: 1

Related Questions