Deployment Rollback and Revision History

A new version of a Deployment turns out broken, and you need an earlier working one back fast. Where exactly is the old version kept, does going back build a new ReplicaSet, and how far back can you still go?

Play the animation 5 steps, animated, plays on a computer or a tablet

Deployment Rollback and Revision History diagram: Deployment rollback and revision history, drawn as two registers of one set

Deployment Rollback and Revision History, step by step

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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

Sources