Skip to content

Instantly share code, notes, and snippets.

@Philmod
Last active July 25, 2021 05:34
Show Gist options
  • Save Philmod/e18056caac485549bb5339ffa4fd31b5 to your computer and use it in GitHub Desktop.
Save Philmod/e18056caac485549bb5339ffa4fd31b5 to your computer and use it in GitHub Desktop.
Deploy a new image from Google Cloud Container Builder to Kubernetes, by storing GKE credentials in GCS.
steps:
- name: 'gcr.io/cloud-builders/npm'
args: ['install']
- name: 'gcr.io/cloud-builders/npm'
args: ['test']
- name: 'gcr.io/cloud-builders/docker'
args: ["build", "-t", "gcr.io/$PROJECT_ID/frontend:$REVISION_ID", "."]
- name: 'gcr.io/cloud-builders/docker'
args: ["push", "gcr.io/$PROJECT_ID/frontend:$REVISION_ID"]
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
gcloud components install kubectl
gsutil cp gs://container-kubernetes-key/kubeconfig .
export KUBECONFIG=kubeconfig
kubectl set image deployment/frontend frontend=gcr.io/$PROJECT_ID/frontend:$REVISION_ID
@popaaaandrei
Copy link

When you get Required "BLABLABLABLA" permission .... message, go into IAM -> Roles -> Create role [ROLE_NAME] -> add container.clusters.get and/or whatever other permissions you need in order to get it done, and assign that role (IAM -> Add) to the Cloud Builder service account ..........@cloudbuild.gserviceaccount.com

Secondly, it works with:

- id: kubectl-set-image
  name: gcr.io/cloud-builders/kubectl
  args: ['set', 'image', 'deployment/[DEPLOYMENT_NAME]', '[IMAGE_NAME]=gcr.io/$PROJECT_ID/[IMAGE_NAME]:$TAG_NAME']
  env:
  - 'CLOUDSDK_COMPUTE_ZONE=[ZONE]'
  - 'CLOUDSDK_CONTAINER_CLUSTER=[CLUSTER]'

@dnsbtchr
Copy link

The previous comment worked for me! Thanks for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment