<p>After a successful</p>
<p><code>kubectl rollout restart deployment/foo</code></p>
<p>the</p>
<p><code>kubectl rollout undo deployment/foo</code></p>
<p>or</p>
<p><code>kubectl rollout undo deployment/foo --to-revision=x</code></p>
<p>are not having effect. I mean, the pods are replaced by new ones and a new revision is created which can be checked with</p>
<p><code>kubectl rollout history deployment foo</code></p>
<p>but when I call the service, the rollback had no effect.</p>
<p>I also tried to remove the <code>imagePullPolicy: Always</code>, guessing that it was always pulling even in the rollback, with no success because probably one thing is not related to the other.</p>
<hr />
<p>Edited: The test is simple, I change the health check route of the http api to return something different in the json, and it doesn't.</p>
<hr />
<p>Edited:</p>
<p>Maybe a typo, but not: I was executing with <code>... undo deployment/foo ...</code>, and now tried with <code>... undo deployment foo ...</code>. It also gives me <code>deployment.apps/foo rolled back</code>, but no changes in the live system.</p>
<p>More tests: I changed again my api route to test what would happen if I executed a rollout undo to every previous revision one by one. I applied the last 10 revisions, and nothing.</p>

Rafael Barros
<p>To be able to rollback to a previous version don't forget to append the <strong>--record</strong> parameter to your kubectl command, for example:</p>
<pre><code>kubectl apply -f DEPLOYMENT.yaml --record
</code></pre>
<p>Then you should be able to see the history as you know with:</p>
<pre><code>kubectl rollout history deployment DEPLOYMENT_NAME
</code></pre>
<p>And your rollback will work properly</p>
<pre><code>kubectl rollout undo deployment DEPLOYMENT_NAME --to-revision=CHOOSEN_REVISION_NUMBER
</code></pre>
<p>Little example:</p>
<p>consider my nginx deployment manifest &quot;nginx-test.yaml&quot; here:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
</code></pre>
<p>lets create it:</p>
<pre><code>❯ kubectl apply -f nginx-test.yaml --record
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/nginx-deployment created
</code></pre>
<p>lets check the image of this deployment, as expected from the manifest:</p>
<pre><code>❯ k get pod nginx-deployment-74d589986c-k9whj -o yaml | grep image:
  - image: nginx
    image: docker.io/library/nginx:latest
</code></pre>
<p>now lets modify the image of this deployment to &quot;nginx:1.21&quot;:</p>
<pre><code>#&quot;nginx=&quot; correspond to the name of the container inside the pod create by the deployment.
❯ kubectl set image deploy nginx-deployment nginx=nginx:1.21.6
deployment.apps/nginx-deployment image updated
</code></pre>
<p>we can optionnaly check the rollout status:</p>
<pre><code>❯ kubectl rollout status deployment nginx-deployment
deployment &quot;nginx-deployment&quot; successfully rolled out
</code></pre>
<p>we can check the rollout history with:</p>
<pre><code>❯ kubectl rollout history deploy nginx-deployment
deployment.apps/nginx-deployment
REVISION  CHANGE-CAUSE
1         kubectl apply --filename=nginx-test.yaml --record=true
2         kubectl apply --filename=nginx-test.yaml --record=true
</code></pre>
<p>lets check the image of this deployment, as expected:</p>
<pre><code>❯ k get pod nginx-deployment-66dcfc79b5-4pk7w -o yaml | grep image:
  - image: nginx:1.21.6
    image: docker.io/library/nginx:1.21.6
</code></pre>
<p>Oh, no, i don't like this image ! Lets rollback:</p>
<pre><code>❯ kubectl rollout undo deployment nginx-deployment --to-revision=1
deployment.apps/nginx-deployment rolled back
</code></pre>
<p>creating:</p>
<pre><code>&gt; kubectl get pod -o wide
NAME                                    READY   STATUS              RESTARTS   AGE     IP           NODE                   NOMINATED NODE   READINESS GATES
pod/nginx-deployment-66dcfc79b5-4pk7w   1/1     Running             0          3m41s   10.244.3.4   so-cluster-1-worker3   &lt;none&gt;           &lt;none&gt;
pod/nginx-deployment-74d589986c-m2htr   0/1     ContainerCreating   0          13s     &lt;none&gt;       so-cluster-1-worker2   &lt;none&gt;           &lt;none&gt;
</code></pre>
<p>after few seconds:</p>
<pre><code>NAME                                    READY   STATUS    RESTARTS   AGE   IP            NODE                   NOMINATED NODE   READINESS GATES
pod/nginx-deployment-74d589986c-m2htr   1/1     Running   0          23s   10.244.4.10   so-cluster-1-worker2   &lt;none&gt;           &lt;none&gt;
</code></pre>
<p>as you can see it worked:</p>
<pre><code>❯ k get pod nginx-deployment-74d589986c-m2htr -o yaml | grep image:
  - image: nginx
    image: docker.io/library/nginx:latest
</code></pre>
<p>lets recheck the history:</p>
<pre><code>❯ kubectl rollout history deploy nginx-deployment
deployment.apps/nginx-deployment
REVISION  CHANGE-CAUSE
1         kubectl apply --filename=nginx-test.yaml --record=true
2         kubectl apply --filename=nginx-test.yaml --record=true
</code></pre>
<p>you can change the rollout history's CHANGE-CAUSE with the &quot;kubernetes.io/change-cause&quot; annotation:</p>
<pre><code>❯ kubectl annotate deploy nginx-deployment kubernetes.io/change-cause=&quot;update image from 1.21.6 to latest&quot; --reco
rd
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/nginx-deployment annotated
</code></pre>
<p>lets recheck the history:</p>
<pre><code>❯ kubectl rollout history deploy nginx-deployment
deployment.apps/nginx-deployment
REVISION  CHANGE-CAUSE
2         kubectl apply --filename=nginx-test.yaml --record=true
3         update image from 1.21.6 to latest
</code></pre>
<p>lets describe the deployment:</p>
<pre><code>❯ kubectl describe deploy nginx-deploy
Name:                   nginx-deployment
Namespace:              so-tests
CreationTimestamp:      Fri, 06 May 2022 00:56:09 -0300
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision: 3
                        kubernetes.io/change-cause: update image from latest to latest
...
</code></pre>
<p>hope this has helped you, bguess.</p>
