<p>Problem</p>

<p>A frequent question that comes up on Slack and Stack Overflow is how to trigger an update to a Deployment/RS/RC when the image tag hasn't changed but the underlying image has.</p>

<p>Consider:</p>

<ol>
<li><p>There is an existing Deployment with image foo: latest</p></li>
<li><p>The user builds a new image foo: latest</p></li>
<li><p>The user pushes foo: latest to their registry</p></li>
<li><p>The user wants to do something here to tell the Deployment to pull the new image and do a rolling-update of existing pods</p></li>
</ol>

<p>For Example: </p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata: 
  name: worker-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: worker
  template:
    metadata:
      labels:
        component: worker
    spec:
      containers:
        - name: worker
          image: stephengrider/multi-worker
          env:
            - name: REDIS_HOST
              value: redis-cluster-ip-service
            - name: REDIS_PORT
              value: "6379"
</code></pre>

<p>And now I have made changes in my multiWorker image</p>

<p>and redeploys the deployment, but it doesn't fetch the latest image?</p>

<p>The <strong>default pull policy is <code>IfNotPresent</code> which causes the Kubelet to skip pulling an image if it already exists</strong>. <a href="https://kubernetes.io/docs/concepts/containers/images/#updating-images" rel="nofollow noreferrer">Refer Link</a></p>

<p>If you would like to always force a pull, you can do one of the following:</p>

<p>1: <strong>set</strong> the <code>imagePullPolicy</code> of the container to <code>Always</code>.</p>

<p>2: <strong>omit</strong> the <code>imagePullPolicy</code> and use <code>:latest</code> as the tag for the image to use.</p>

<p>3: <strong>omit</strong> the <code>imagePullPolicy</code> and the tag for the image to use.</p>

<p>4: <strong>enable</strong> the <code>AlwaysPullImages</code> admission controller.</p>

<blockquote>
  <p>Note that you should <strong>avoid using :latest tag</strong>, we should avoid using the :latest tag when deploying containers in production as it is harder to track which version of the image is running and more difficult to roll back properly.</p>
</blockquote>

<p>Various <code>imagePullPolicy</code> and the <code>tag</code> of the image affect when the kubelet attempts to pull the specified image listed below. <a href="https://kubernetes.io/docs/concepts/configuration/overview/#container-images" rel="nofollow noreferrer">Refer Link for Details</a></p>

<p>1) imagePullPolicy: IfNotPresent: the image is pulled only if it is not already present locally.</p>

<p>2) imagePullPolicy: Always: the image is pulled every time the pod is started.</p>

<p>3) imagePullPolicy is omitted and either the image tag is :latest or it is omitted: Always is applied.</p>

<p>4) imagePullPolicy is omitted and the image tag is present but not :latest: IfNotPresent is applied.</p>

<p>5) imagePullPolicy: Never: the image is assumed to exist locally. No attempt is made to pull the image.</p>
