Sub topic 11
Pausing and Resuming a Rollout
This chapter assumes you can apply manifests and use kubectl get, and that you know a Deployment creates a new ReplicaSet whenever its Pod template changes. Each template edit normally starts its own rollout. Pausing a Deployment lets you make several edits and roll them out together as one revision.
Why pause a rollout
Suppose you want to change the image and also set resource limits. If you run two separate commands on a live Deployment, Kubernetes starts a rollout after the first one. The second command then starts another rollout while the first is still in progress. You get two revisions, two sets of Pod replacements, and a half-configured version running in between.
A paused Deployment still accepts edits. The Deployment controller records the new spec but does not create a new ReplicaSet or change any Pods. When you resume, it sees the final template and performs a single rollout.
The workflow
kubectl rollout pause deployment/web
kubectl set image deployment/web web=nginx:1.27
kubectl set resources deployment/web -c web --limits=cpu=500m,memory=256Mi
kubectl rollout resume deployment/web
kubectl rollout status deployment/webpausesetsspec.pausedtotrueon the Deployment.set imageandset resourcesedit the Pod template. No Pods change.resumesetsspec.pausedback tofalse. The controller creates one new ReplicaSet containing both changes and starts the rolling update.rollout statusfollows the rollout until it completes.
Checking the state while paused
While paused, confirm that nothing has rolled out yet:
kubectl get deployment web -o jsonpath='{.spec.paused}{"\n"}'
kubectl get replicasets -l app=web
kubectl rollout history deployment/webThe first command prints true. The ReplicaSet list still shows only the old ReplicaSet with Pods, and the history has no new revision. The spec you see with kubectl get deployment web -o yaml already contains your edits, but the running Pods do not.
What pausing does not cover
Pausing only affects changes to the Pod template. Edits to other fields still take effect immediately. Changing spec.replicas, for example, scales the current ReplicaSet even while the Deployment is paused.
Other behaviors to know:
kubectl rollout statuson a paused Deployment reports that it is paused and waiting for resume. It does not finish until you resume.kubectl rollout undodoes not work on a paused Deployment. The command fails with an error telling you to resume first. Resume the Deployment before you roll back.- The progress deadline does not run while a Deployment is paused, so a paused Deployment is not marked as failed.
- Pausing does not stop a rollout that is already moving Pods in a way that undoes work. If you pause mid-rollout, the controller stops creating and removing Pods, and the Deployment keeps a mix of old and new Pods until you resume.
Common errors
- Forgetting to resume. Edits pile up and nothing deploys. If a change seems to have no effect, check
spec.paused. - Expecting a canary. Pausing mid-rollout leaves some new Pods running, but the split is not controlled, and Services route to old and new Pods alike. Use a purpose-built approach for real canaries (see the later chapter on progressive delivery).
- Editing with
kubectl applywhile paused. Re-applying a manifest that containspaused: trueor omits it can change the paused state. If your manifest does not mentionpaused,applyleaves the field as it is, but check this in your own workflow.
Exercise
You run kubectl rollout pause deployment/web, then kubectl set image deployment/web web=nginx:1.27, and then kubectl scale deployment/web --replicas=6. What happens to the Pods right after the scale command, and when does the image change reach the Pods?
Show answer
The scale takes effect immediately, because pausing only blocks rollouts triggered by Pod template changes. The current ReplicaSet gets 6 replicas of the old image. The image change reaches the Pods only after kubectl rollout resume deployment/web, which creates a new ReplicaSet and starts one rolling update.
Exercise
Why can't you run kubectl rollout undo on a paused Deployment, and what do you do first?
Show answer
A paused Deployment does not process template changes, so a rollback to an earlier template would have no effect. The command is rejected. Run kubectl rollout resume deployment/web first, then run kubectl rollout undo.