Technotes

Technotes for future me

Kubernetes rollout history and rollback

Check rollout history

One useful feature of deployments is the ability to track the rollout history. To view rollout history, use the following command:

kubectl rollout history deployment/whoami

Output:

deployment.apps/whoami
REVISION  CHANGE-CAUSE
1         <none>
2         <none>
3         <none>

Get details on a particular revision with:

kubectl rollout history deployment.v1.apps/whoami --revision=1

Output:

deployment.apps/whoami with revision #1
Pod Template:
  Labels:       app=whoami
        pod-template-hash=55df66c545
  Containers:
   whoami:
    Image:      containous/whoami
    Port:       80/TCP
    Host Port:  0/TCP
    Limits:
      cpu:      500m
      memory:   256Mi
    Requests:
      cpu:      250m
      memory:   64Mi
    Environment:        <none>
    Mounts:     <none>
  Volumes:      <none>

Rollback deployment

Suppose you have made some changes to your deployment that you want to roll back. To do this, use the following command:

kubectl rollout undo deployment/whoami --to-revision=2

Output:

deployment.apps/whoami rolled back

Also check the pods list, you will see following output, where deployment controller trying to reconcile the status.

kubectl get pods -l app=whoami
NAME           READY  STATUS       RESTARTS  AGE
whoami-68d45cc4b6-cm2hz  1/1   Running       0     85s
whoami-68d45cc4b6-dkwd8  1/1   Running       0     81s
whoami-68d45cc4b6-pzkx7  1/1   Running       0     85s
whoami-68d45cc4b6-znqgn  1/1   Terminating     0     82s
whoami-74bb7f5f9f-ds8qs  0/1   ContainerCreating  0     2s
whoami-74bb7f5f9f-g4nqq  1/1   Running       0     2s
whoami-74bb7f5f9f-rdl5h  0/1   Pending       0     0s
whoami-74bb7f5f9f-rrbfs  0/1   ContainerCreating  0     2s

Source:
https://www.goglides.dev/bkpandey/checking-rollout-history-rollback-of-a-deployment-3c9m

Last updated on 19 May 2023
Published on 19 May 2023
Edit on GitHub