<p>I am using Deployments to control my pods in my K8S cluster.</p>

<p>My original deployment file looks like :</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: websocket-backend-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      name: websocket-backend
  template:
    metadata:
      labels:
        name: websocket-backend
    spec:
      containers:
      - name: websocket-backend
        image: armdock.se/proj/websocket_backend:3.1.4
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 8080
        livenessProbe:
          httpGet:
            port: 8080
            path: /websocket/health
          initialDelaySeconds: 300
          timeoutSeconds: 30
        readinessProbe:
          httpGet:
            port: 8080
            path: /websocket/health
          initialDelaySeconds: 25
          timeoutSeconds: 5
</code></pre>

<p>This config is working as planned. </p>

<pre><code># kubectl get po | grep websocket
websocket-backend-deployment-4243571618-mreef                     1/1       Running            0          31s
websocket-backend-deployment-4243571618-qjo6q                     1/1       Running            0          31s
</code></pre>

<p>Now I plan to do a live/rolling update on the image file.
The command that I am using is :</p>

<pre><code>kubectl set image deployment  websocket-backend-deployment websocket-backend=armdock.se/proj/websocket_backend:3.1.5
</code></pre>

<p>I am only updating the docker image tag.
Now im expecting for my pods to remain 2 after the update. I am getting the 2 new pods with the new version but there is one pod that still exists carrying the old version.</p>

<pre><code># kubectl get po | grep websocket
websocket-backend-deployment-4243571618-qjo6q                     1/1       Running            0          2m
websocket-backend-deployment-93242275-kgcmw                       1/1       Running            0          51s
websocket-backend-deployment-93242275-kwmen                       1/1       Running            0          51s
</code></pre>

<p>As you can see, 1 pod uses the old tag <code>3.1.4</code></p>

<pre><code># kubectl describe po websocket-backend-deployment-4243571618-qjo6q | grep Image:
    Image:      armdock.se/proj/websocket_backend:3.1.4
</code></pre>

<p>The rest of the 2 nodes are on the new tag <code>3.1.5</code>.</p>

<pre><code># kubectl describe po websocket-backend-deployment-93242275-kgcmw | grep Image:
    Image:      armdock.se/proj/websocket_backend:3.1.5
# kubectl describe po websocket-backend-deployment-93242275-kwmen | grep Image:
    Image:      armdock.se/proj/websocket_backend:3.1.5
</code></pre>

<p>Why does 1 old pod still stay there and doesnt get deleted ? Am I missing some config ? </p>

<p>When I check the <code>rollout</code> command, its just stuck on :</p>

<pre><code># kubectl rollout status deployment/websocket-backend-deployment
Waiting for rollout to finish: 1 old replicas are pending termination...
</code></pre>

<p>My K8S version is :</p>

<pre><code># kubectl --version
Kubernetes v1.5.2
</code></pre>

<p>I would suggest you to set the <strong>maxSurge</strong> to 0 in the RollingUpdate strategy to make the desired pods same after the rollout . The maxSurge parameter is the maximum number of pods that can be scheduled above the original number of pods. </p>

<p>Example:  </p>

<pre class="lang-sh prettyprint-override"><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
   name: webserver
spec:
   replicas: 2
   selector:
      matchLabels:
         name: webserver
   strategy:
      type: RollingUpdate
      rollingUpdate:
         maxSurge: 0
         maxUnavailable: 1
   template:
      metadata:
         labels:
            name: webserver
      spec:
         containers:
            - name: webserver
              image: nginx:latest
              imagePullPolicy: IfNotPresent
              ports:
                - containerPort: 80
</code></pre>
