Rolling updates and rollback
Change a version while serving requests
A rolling update replaces the application Pods in stages. Changing the Pod template, such as a container image, initiates a rollout when the Deployment is not paused. The Deployment can use a new ReplicaSet or reuse one with the same template. Scaling alone does not introduce a new template revision. All examples are offline teaching material. The image registry and versions are deliberately non-deployable placeholders. No cluster, image or kubeconfig is included. Commands are static illustrations for a separately approved disposable cluster with verified ./lab.kubeconfig, bytemind-lab context, book-lab namespace, permissions and reviewed pinned images. Never run these against an unknown context.
Set rollout budgets
For four desired replicas, allow one extra Pod and one unavailable replica. The controller aims to keep at least three available replicas and target at most five non-terminating replicas during ordinary rollout operations. Independent failures may reduce actual availability; terminating Pods may temporarily increase total resource use. A ready Pod counts as available after the configured minimum ready interval.
apiVersion: apps/v1kind: Deploymentmetadata: name: catalog namespace: book-labspec: replicas: 4 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 1 selector: matchLabels: app: catalog template: metadata: labels: app: catalog spec: containers: - name: catalog image: registry.example.invalid/learning/catalog:2 resources: requests: cpu: 50m memory: 32Mi limits: cpu: 100m memory: 64MiCompare rollout-v1.yaml and rollout-v2.yaml. Only the image changes. Both specify RollingUpdate; Recreate instead removes old Pods before creating new ones for a template update and may cause downtime.
Calculate integer and percentage budgets
For an ordinary rolling update, percentage surge is rounded upward and percentage unavailable downward. With three replicas and 25% for each, surge is one and unavailable is zero. With seven replicas, the same percentages yield two and one. The two budgets cannot both resolve to an explicitly configured zero; consult the selected version for edge cases such as zero desired replicas.
These snapshots omit intermediate transitions and terminating Pods. They show one possible progression, not guaranteed controller ordering. A new Pod that never becomes ready may stall the rollout.
Observe before deciding to roll back
A bounded status wait is useful, but a successful rollout is only a controller-level signal. A timeout does not automatically undo anything. A progress deadline can report a failed progression; investigate events, Pods and app behavior. Retained ReplicaSets hold revision history, so an old revision may no longer be available.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab rollout status deployment/catalog --timeout=60skubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab rollout history deployment/catalogkubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab describe deployment/catalogStatus is not a test of catalog responses. Review an application-level check separately. A rollback is a mutation; inspect the target revision before any separately authorized change.
Restore a template, not the database
In an approved lab with retained revision 1, the syntax below requests restoration of that revision’s template. It does not reverse database changes, messages, external configuration or every other field in the Deployment. A version-controlled declaration must also be reconciled with the intended recovery so it does not reintroduce the faulty version.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab rollout undo deployment/catalog --to-revision=1The command is not executed here. After an approved rollback, check controller status and application behavior, and handle data compatibility separately.
Practice: review a release
Use lab-fixtures/deployments/rollout-timeline.json to check the selected rows against the budgets. Calculate the two percentage cases and explain what a stalled update means. Identify two checks beyond readiness before declaring a release successful.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Rolling updates and rollback — knowledge check
Apply the lesson concepts to original offline scenarios.
Four desired replicas and maxSurge=1 allow how many non-terminating replicas as a rollout target?
Seven desired replicas with maxUnavailable=25% gives what budget?
Which change normally starts a new Deployment rollout?
A rollout status wait times out. What should you infer?
What does undo to a retained revision restore?