<p>I am currently trying to implement the CI/CD pipeline using docker , Kubernetes and Jenkins. When I created the pipeline deployment Kubernetes deployment YAML file, I was not included the time stamp. Only I was using the imagePullPolicy as <code>latest</code> in YAML file. Regarding with latest pull I had already one discussion here, The following is the link for that discussion,</p>

<p><a href="https://stackoverflow.com/questions/58539362/docker-image-not-pulling-latest-from-dockerhub-com-registry?noredirect=1#comment103401768_58539362">Docker image not pulling latest from dockerhub.com registry</a></p>

<p>After This discussion , I included the time stamp in my deployment YAML like the following,</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-kube-deployment
  labels:
   app: test-kube-deployment
spec:
 replicas: 3
 selector:
  matchLabels:
    app: test-kube-deployment
 template:
  metadata:
    labels:
      app: test-kube-deployment
    annotations: 
     date: "+%H:%M:%S %d/%m/%y"
  spec:
    imagePullSecrets:
      - name: "regcred"
    containers:
     - name: test-kube-deployment-container
       image: spacestudymilletech010/spacestudykubernetes:latest
       imagePullPolicy: Always
       ports:
         - name: http
           containerPort: 8085
           protocol: TCP
</code></pre>

<p>Here I modified my script to include the time stamp by adding the following in template, </p>

<pre><code>annotations: 
    date: "+%H:%M:%S %d/%m/%y"
</code></pre>

<p>My service file like following,</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  ports:
   - port: 8085
     targetPort: 8085
     protocol: TCP
     name: http
 selector:
    app: test-kube-deployment
</code></pre>

<p>My jenkinsfile conatining  the following,</p>

<pre><code>stage ('imagebuild')
            {
                steps
                    {                               
 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'
                    }
            }

  stage ('Test Deployment')
            {
                 steps
                    {
                        sh 'kubectl apply -f deployment/testdeployment.yaml'
                        sh 'kubectl apply -f deployment/testservice.yaml'
                    }
            }
</code></pre>

<p>But still the deployment not pulling the latest one from Dockerhub registry. How I can modify these script for resolving the latest pulling problem?</p>

Mr.DevEng
<pre><code>The default pull policy is IfNotPresent which causes the Kubelet to skip pulling an image if it already exists. If you would like to always force a pull, you can do one of the following:

set the imagePullPolicy of the container to Always.

omit the imagePullPolicy and use :latest as the tag for the image to use.

omit the imagePullPolicy and the tag for the image to use.

enable the AlwaysPullImages admission controller.
</code></pre>

<p>Basically, either use <code>:latest</code> or then use <code>imagePullPolicy: Always</code> </p>

<p>Try it and let me know how it goes!</p>

<p>Referenced from <a href="https://kubernetes.io/docs/concepts/containers/images/" rel="nofollow noreferrer">here</a> </p>
