Deployment Rollback and Revision History
A rollout went bad, so how do you get back to what worked? A revision is not a snapshot the Deployment stores, it is a ReplicaSet with a revision annotation, kept at zero once it is old, so a rollback copies that template back and the matching ReplicaSet is scaled up and renumbered forward rather than a fifth being created. A pruned ReplicaSet takes its revision with it, so revisionHistoryLimit, 2 on this Deployment and 10 by default, caps how far back you can go.
Play the animation 5 steps, animated, best on a wide screen
Deployment Rollback and Revision History, step by step
-
A revision is not a snapshot the Deployment keeps, it is one of these ReplicaSets. You run kubectl set image and no ReplicaSet carries the new template, so the controller creates one, named by that template hash, and annotates it revision 4. A fourth row joins rollout history, pointing at the object that carries the number.
Play from step 1 -
Revision 4 is broken. Its ReplicaSet never reaches its Ready count, so the rollout makes no progress, and once progressDeadlineSeconds has elapsed the Deployment reports Progressing=False with the reason ProgressDeadlineExceeded. The ReplicaSet holding app:v2.0 is still the one serving.
Play from step 2 -
Running kubectl rollout undo steps back one revision by default, and --to-revision names any revision still in the list. Here it takes revision 2, which copies the template that ReplicaSet froze back into .spec.template. Nothing is created or deleted, and the history has not moved yet.
Play from step 3 -
The restored template matches a ReplicaSet already on the shelf, so no fifth one is made. The controller annotates that object revision 5, scales it up and the two newer ones to zero. Revision 2 leaves the list, revision 5 joins the end, and the connectors cross: the newest revision points at an object created long before it.
Play from step 4 -
Three old ReplicaSets now sit at zero, one more than revisionHistoryLimit allows. It is 2 on this Deployment and 10 by default, and once the rollout completes the controller deletes the lowest revision. The object goes and its row leaves the list with it, so revision 1 can no longer be reached.
Play from step 5