kubernetes: Rollback a deployment update

2 min read | by Jordi Prats

When performing rolling updates we can see it's history using kubectl rollout history:

$ kubectl rollout history deploy pet2cattle
deployment.apps/pet2cattle 
REVISION  CHANGE-CAUSE
100       <none>
101       <none>
102       <none>
103       <none>
104       <none>
105       <none>
106       <none>
107       <none>
109       kubectl scale deployment/pet2cattle --replicas=2 --record=true
110       kubectl scale deployment/pet2cattle --replicas=5 --record=true
111       kubectl scale deployment/pet2cattle --replicas=1 --record=true

If have any problem with the update we can undo and update using kubectl rollout undo

To rollback to a specific revision we just need to specify to which revision on the history we want to rollback using the option --to-revision and the revision number we can find on the kubectl rollout history. For example:

$ kubectl rollout undo --to-revision 109 deployment/pet2cattle
deployment.apps/pet2cattle rolled back

If we don't specify any specific revision, it will rollback to the last version. Checking again the kubectl rollout history we won't be able to see an explicit rollback:

$ kubectl rollout history deploy pet2cattle
deployment.apps/pet2cattle 
REVISION  CHANGE-CAUSE
100       <none>
101       <none>
102       <none>
103       <none>
104       <none>
105       <none>
106       <none>
107       <none>
110       kubectl scale deployment/pet2cattle --replicas=5 --record=true
111       kubectl scale deployment/pet2cattle --replicas=1 --record=true
112       kubectl scale deployment/pet2cattle --replicas=2 --record=true

Instead, the revision we have rollback to is no longer available since it's revision number have been updated to be the latest (Notice the number of replicas)


Posted on 25/05/2021