Deployment Rolling Update
You ship a new image to a Deployment, and its Pods are swapped for new ones while the app keeps answering. How many may be extra or missing at any moment, and what has to happen before an old Pod may go?
Play the animation 6 steps, animated, plays on a computer or a tablet
Deployment Rolling Update, step by step
-
You run kubectl set image deployment/web app=web:v2.0, which PATCHes .spec.template. The Deployment hashes that template into a new pod-template-hash and creates a second ReplicaSet, RS-v2, already at replicas 1, the one surge slot the 25% maxSurge allows. RS-v1 still owns all 3 live Pods.
Play from step 1 -
RS-v2 wants 1 replica and owns no Pod yet, so the ReplicaSet controller creates one through the API, in the RS-v2 column. No old Pod has to leave first, because that create already spent the surge slot. While the new Pod starts, the fleet runs to 4 live Pods, one over .spec.replicas.
Play from step 2 -
The new Pod passes its readinessProbe and RS-v2 reports Ready 1. At the default minReadySeconds 0 the Pod counts as available at once. Since maxUnavailable is 0, the Deployment may not touch RS-v1 until a replacement is Ready, and that is exactly what keeps 3 Pods serving throughout.
Play from step 3 -
Only now does the Deployment scale RS-v1 from 3 to 2 through the API, and the ReplicaSet controller deletes one old RS-v1 Pod, which starts graceful termination. Terminating Pods do not count as available, so the 3 Pods that maxUnavailable 0 requires are the 2 old Ready Pods plus the new one.
Play from step 4 -
The same trio runs again for the second replica. RS-v2 grows to 2 and the new Pod starts in the next slot, and only once that Pod reports Ready does RS-v1 drop to 1 and let another old Pod go. The window of live Pods has slid one slot to the right and never narrowed below 3.
Play from step 5 -
The last replica crosses the same way. RS-v2 reaches 3 Ready and RS-v1 ends at replicas 0, kept up to revisionHistoryLimit so kubectl rollout undo can roll back. No old Pod is running any more, so the rollout is complete, with Available=True and Progressing NewReplicaSetAvailable.
Play from step 6