Solution skill
How to run kubectl after docker push in Google Cloud Build
Complete solution
Walks through run kubectl after docker push in Google Cloud Build, step by step. Use it when you need to do exactly this. Not a troubleshooting guide, so skip it if you are here because of an error.
TL;DR
How to run kubectl after pushing an image in a Cloud Build pipeline? Chain build steps explicitly: run docker push as its own build step (rather than relying only on the images: field), then add a gcr.io/cloud-builders/kubectl step that deploys the pushed image.
Steps
- How to run kubectl after pushing an image in a Cloud Build pipeline? The goal: build an image, test/push it to GCR, then deploy it into a GKE cluster, all in one cloudbuild.yaml. Without this, the pipeline could not do end-to-end CI/CD.
- Chain build steps explicitly: run
docker pushas its own build step (rather than relying only on theimages:field), then add agcr.io/cloud-builders/kubectlstep that deploys the pushed image. A working community pattern confirmed in the thread: - steps:
name: 'gcr.io/cloud-builders/docker' args: ['build', '-t', 'gcr.io/$PROJECTID/my-project:$TAGNAME', '.']
name: 'gcr.io/cloud-builders/docker' args: ['push', 'gcr.io/$PROJECTID/my-project:$TAGNAME']
name: 'gcr.io/cloud-builders/kubectl' args: ['set', 'image', 'deployment/my-deploy', 'my-container=gcr.io/$PROJECTID/my-project:$TAGNAME']
- Note the images: field pushes separately, so pushing manually avoids double pushes if you push in a step. The kubectl step needs the build service account to have the right scopes/roles to talk to the GKE cluster.
- The thread above nails the cause, so the fix addresses that directly rather than symptoms. Adapt the version numbers and paths to your setup, then verify the behavior the thread confirmed.
When to use
You are seeing this: The goal: build an image, test/push it to GCR, then deploy it into a GKE cluster, all in one cloudbuild.yaml. Use this skill when you run into "How to run kubectl after docker push in Google Cloud Build".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The thread above nails the cause, so the fix addresses that directly rather than symptoms.
Sources
- https://github.com/GoogleCloudPlatform/cloud-builders/issues/22
Evidence
Asked in the thread (https://vectle.com/threads/thrctEpbyoA8nCq9xivP6E4w): How to run kubectl after pushing an image in a Cloud Build pipeline? The goal: build an image, test/push it to GCR, then deploy it into a GKE cluster, all in one cloudbuild.yaml. Without this, the pipeline could not do end-to-end CI/CD. Verified resolution: Chain build steps explicitly: run docker push as its own build step (rather than relying only on the images: field), then add a gcr.io/cloud-builders/kubectl step that deploys the pushed image. A working community pattern confirmed in the thread:
steps:
name: 'gcr.io/cloud-builders/docker' args: ['build', '-t', 'gcr.io/$PROJECTID/my-project:$TAGNAME', '.']
name: 'gcr.io/cloud-builders/docker' args: ['push', 'gcr.io/$PROJECTID/my-project:$TAGNAME']
name: 'gcr.io/cloud-builders/kubectl' args: ['set', 'image', 'deployment/my-deploy', 'my-container=gcr.io/$PROJECTID/my-project:$TAGNAME']
Note the images: field pushes separately, so pushing manually avoids double pushes if you push in a step. The kubectl step needs the build service account to have the right scopes/roles to talk to the GKE cluster.
Source: https://github.com/GoogleCloudPlatform/cloud-builders/issues/22
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_bN49hETyXwpkiryW42CREA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">How to run kubectl after docker push in Google Cloud Build <span>— Vectle</span></a>