<p>When I am implementing the CI/CD pipeline, I am using docker, kubernetes and jenkins for implementation. And I am pushing the resulting Docker image to Dockerhub repository.</p>

<p>When I am pulling it is not pulling the latest from the Dockerhub.com registry. So it's not showing the updated response in my application. I added the <code>testdeployment.yaml</code> file like the following. And repository credentials are storing in Jenkinsfile only.</p>

<pre><code>spec:
  containers:
   - name: test-kube-deployment-container
     image: "spacestudymilletech010/spacestudykubernetes:latest"
     imagePullPolicy: Always
     ports:
        - name: http
          containerPort: 8085
          protocol: TCP
</code></pre>

<p>Jenkinsfile </p>

<pre><code> sh 'docker build -f /var/lib/jenkins/workspace/jpipeline/pipeline/Dockerfile -t spacestudymilletech010/spacestudykubernetes:latest /var/lib/jenkins/workspace/jpipeline/pipeline'
 sh 'docker login --username=&lt;my-username&gt; --password=&lt;my-password&gt;' 
 sh 'docker push spacestudymilletech010/spacestudykubernetes:latest'
</code></pre>

<p>How can I identify why it is not pulling latest image from the Dockerhub.com?</p>

<p>It looks like you are repeatedly pushing <code>:latest</code> to dockerhub?</p>

<p>If so, then that's the reason for your issue. You push latest to the hub from your Jenkins job, but if the k8s node which runs the deployment pod already has a tag called <code>latest</code> stored locally, then that's what it will use.</p>

<p>To clarify - <code>latest</code> is just a string, it could equally well be <code>foobar</code>. It doesn't actually <em>mean</em> that docker will pull the most recent version of the container.</p>

<p>There are two takeaways from this:</p>

<ul>
<li>It's almost always a very bad idea to use <code>latest</code> in k8s.</li>
<li>It <em>is</em> always a bad idea to push the same tag multiple times, in fact many repo's won't let you.</li>
</ul>

<p>With regards to using <code>latest</code> at all. This comes from personal experience, at my place of work, in the early days of our k8s adoption, we used it everywhere. That is until we found one day that our puppet server wasn't working any more. On investigation we found that the node had died, the pod re-spun on a different node and a different <code>latest</code> was pulled which was a new major release, breaking things.</p>

<p>It was not obvious, because <code>kubectl describe pod</code> showed the same tag name as before so nothing, apparently, had changed.</p>

<p>To add an excellent point mentioned in the comments:
You have <code>ImagePullPolicy: 'Always'</code>, but if you're doing <code>kubectl apply -f mypod.yaml</code>, with the same tag name, k8s has no way of knowing you've actually changed the image</p>
