Sub topic 16
Pausing a rollout to batch several changes
This chapter assumes you can write a Deployment manifest and run kubectl apply, kubectl set image and kubectl rollout status. It also assumes you know that a change to the Pod template creates a new ReplicaSet.
Why batching matters
Every edit to a Deployment's Pod template triggers a new rollout. If you change the image, then the resource limits, then an environment variable, you can get three rollouts in a row. Each one creates a new ReplicaSet and a new revision. Each one also replaces Pods that the next change will replace again.
You can avoid this by pausing the Deployment, making all your edits, and then resuming it. The changes then roll out together as one new revision.
How pausing works
A paused Deployment (spec.paused: true) still accepts changes to its spec. The Deployment controller records them but does not act on Pod template changes. No new ReplicaSet is created, and no Pods are replaced. When you resume, the controller sees the final template and starts one rolling update.
Batching changes with kubectl
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/webWhile the Deployment is paused, check that nothing has rolled out:
kubectl get rs -l app=web
kubectl rollout status deployment/webYou should still see only the old ReplicaSet with all its Pods. After kubectl rollout resume deployment/web, run kubectl rollout status deployment/web to watch the single rollout finish. kubectl get rs -l app=web then shows the new ReplicaSet at full strength and the old one at zero.
Common errors
- Forgetting to resume. Edits sit unapplied and the cluster keeps running the old version. If a rollout seems to do nothing, run
kubectl get deployment web -o jsonpath='{.spec.paused}'. A result oftruemeans the Deployment is paused. - Expecting
rollout undoto work while paused. A paused Deployment cannot be rolled back. Resume it first, then runkubectl rollout undo. - Expecting scaling to pause. Changing
replicasis not a Pod template change. Scaling still takes effect while the Deployment is paused. - Waiting on a paused rollout.
kubectl rollout statusdoes not finish on a paused Deployment that has a pending change. It reports that the rollout is paused.
Exercise
You run kubectl rollout pause deployment/web, then kubectl set image deployment/web web=nginx:1.27, and nothing happens to your Pods. How many ReplicaSets does the Deployment own now, and what must you do to start the update?
Show answer
The Deployment still owns the same ReplicaSets as before, because a paused Deployment creates no new ReplicaSet for template changes. Run kubectl rollout resume deployment/web. This starts a single rolling update that applies the new image and any other changes made during the pause.