<p>Hi i am trying to deploy on my gke cluster through cloud build.I am able to deploy. But every time i am pushing new images.My cluster is not picking up the new image but deploy the pod with the old image only(nothing is changed).When i am deleting my pod and triggering the cloudbuild then it is picking the new image. I have also added ImagePullPolicy= Always.
Below is my cloudbuild.yaml file.</p>
<pre><code>  - id: 'build your instance'
name: 'maven:3.6.0-jdk-8-slim'
entrypoint: mvn
args: ['clean','package','-Dmaven.test.skip=true']
- id: &quot;docker build&quot;  
name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/PID/test', '.']
name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/PID/TEST']
- id: 'Deploy image to kubernetes'
name: 'gcr.io/cloud-builders/gke-deploy'
args:
- run
- --filename=./run/helloworld/src
- --location=us-central1-c
- --cluster=cluster-2
</code></pre>
<p>My pod manifest  looks like this.</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: Test
  labels:
     app: hello
spec:
  containers:
   - name: private-reg-containers
     image: gcr.io/PID/test
     imagePullPolicy: &quot;Always&quot;
</code></pre>
<p>Any help is appreciated.</p>

Abhinav
<p>This is an expected behavior and you may be confusing the usage of <code>imagePullPolicy: &quot;Always&quot;</code>. This is well explanined in this <a href="https://stackoverflow.com/a/45906651/12265927">answer</a>:</p>
<blockquote>
<p>Kubernetes is not watching for a new version of the image. The image pull policy specifies how to acquire the image to run the container. Always means it will try to pull a new version each time it's starting a container. To see the update you'd need to delete the Pod (not the Deployment) - the newly created Pod will run the new image.
<br />
<br />
There is no direct way to have Kubernetes automatically update running containers with new images. This would be part of a continuous delivery system (perhaps using kubectl set image with the new sha256sum or an image tag - but not latest).</p>
</blockquote>
<p>This is why when you recreate the pods, those get the newest image. So the answer to your question is to explicitly tell K8s to get the newest image. In the example I share with you I use two tags, the clasic <code>latest</code> which is more used to share the image with a friendly name and the tag using the <code>$BUILD_ID</code> which is used to update the image in GKE. In this example I update the image for a deployment so you only change it for updating an standalone pod which should be your little &quot;homework&quot;.</p>
<pre class="lang-yaml prettyprint-override"><code>steps:

#Building Image
- name: 'gcr.io/cloud-builders/docker'
  id: build-loona
  args: 
  - build
  - --tag=${_LOONA}:$BUILD_ID
  - --tag=${_LOONA}:latest
  - .
  dir: 'loona/'
  waitFor: ['-']

#Pushing image (this pushes the image with both tags)
- name: 'gcr.io/cloud-builders/docker'
  id: push-loona
  args:
  - push
  - ${_LOONA}
  waitFor:
    - build-loona

#Deploying to GKE
- name: &quot;gcr.io/cloud-builders/gke-deploy&quot;
  id: deploy-gke
  args:
  - run
  - --filename=k8s/
  - --location=${_COMPUTE_ZONE}
  - --cluster=${_CLUSTER_NAME}

#Update Image
- name: 'gcr.io/cloud-builders/kubectl'
  id: update-loona
  args:
  - set
  - image
  - deployment/loona-deployment
  - loona=${_LOONA}:$BUILD_ID
  env:
  - 'CLOUDSDK_COMPUTE_ZONE=${_COMPUTE_ZONE}'
  - 'CLOUDSDK_CONTAINER_CLUSTER=${_CLUSTER_NAME}'
  waitFor:
    - deploy-gke

substitutions:
    _CLUSTER_NAME: my-cluster
    _COMPUTE_ZONE: us-central1
    _LOONA: gcr.io/${PROJECT_ID}/loona

</code></pre>
