<p>I'm having jenkins stage to deploy kubernetes manifest file with rolling RollingUpdate method and i configured maxSurgeand and maxUnavailable value with 4 replicas copy of pod. while running jenkins my kubernetes yaml file is applying but after the deployment new changes been not reflecting.</p>
<p>In this case i need to login to worker node where my pod is running, then i need stop the deployment then i need to use docker rmi command to remove the container, finally i need pull the latest image to reflect the new changes.</p>
<p>jenkins file</p>
<pre><code>stage('Deploy') {
        container('kubectl') {
            withCredentials([kubeconfigFile(credentialsId: 'KUBERNETES_CLUSTER_CONFIG', variable: 'KUBECONFIG')]) {
                def kubectl
                echo 'deploy to deployment!!'
                if(gitBranch == &quot;devops&quot;) {
                    kubectl = &quot;kubectl --kubeconfig=${KUBECONFIG} --context=arn:aws:eks:eu-central-1:123456789101:cluster/my-modulus-cluster&quot;
                    echo 'deploy to my-modulus-cluster!'
                    sh &quot;kubectl apply -f ./infrastructure/dev/my.yaml -n default --record&quot;
                    sh &quot;kubectl rollout history deployment myapp&quot;
                    }
            }
        }
    }
</code></pre>
<p>Here the k8 manifest file</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5
  template:
    metadata:
      labels:
        app: myapp
    spec:
      backend
      containers:
      - name: myapp
        image: myimage:latest
        imagePullPolicy: Always
        ports:
            - containerPort: 3030
        readinessProbe:
          initialDelaySeconds: 1
          periodSeconds: 2
          timeoutSeconds: 1
          successThreshold: 1
          failureThreshold: 1
          httpGet:
            host:
            scheme: HTTPS
            path: /
            httpHeaders:
            - name: Host
              value: myhost
            port: 3030
</code></pre>

Gowmi
<p>Inside the deploy stage i have added if condition to set image</p>
<pre><code>sh 'echo &quot;Starting ams Deployment&quot;'
                    sh '''
                        if kubectl get deployments | grep ams
                        then
                            kubectl set image deployment ams ams=myimage:latest
                            kubectl rollout restart deployment ams
                        else
                            kubectl apply -f my.yaml -n default
                        fi
                    '''
</code></pre>
