Deployment rollback
What you will learn
Rolling deployments replace instances gradually while old and new versions may serve requests at the same time. A rollback restores an earlier workload template, but does not automatically undo database changes or external effects. Treat compatibility and rollback as tested release contracts.
- Explain rolling updates and explicit rollback gates.
- Test old/new schema compatibility during overlap.
- Design a rollback decision using artifact identity and health evidence.
Plain Java examples: save as Main.java in a fresh directory, then run javac --release 21 Main.java and java Main. Standalone Java 21 functional examples. Docker and Kubernetes recipes are source-reviewed, not executed. Companion local HTTP/JDK evidence is separate.
Check overlap compatibility
public class Main { static boolean compatible(int min,int max,int schema){if(min>max)throw new IllegalArgumentException();return schema>=min&&schema<=max;} public static void main(String[] args) { System.out.println(compatible(1,2,2)); System.out.println(compatible(2,3,2)); System.out.println(compatible(1,2,3)); }}Expected output:
truetruefalseBoth releases accept schema 2, but the old release cannot accept schema 3.
Rollout controls
A Deployment manages ReplicaSets and a rolling update can use maxSurge and maxUnavailable. Readiness gates traffic but does not guarantee zero downtime. The companion manifest uses two replicas, maxUnavailable 0 and maxSurge 1; capacity for an extra Pod is required. Progress deadlines report stalled rollouts; they do not automatically undo a deployment. Preserve known-good image digests and configuration revisions. Use explicit lab namespace/context only; no cluster operation is executed here.
Expand, migrate, contract
Add compatible schema first, deploy code able to operate during overlap, backfill safely with observable progress, then remove obsolete columns only after old versions and rollback window are gone. A failed readiness check, high error rate or compatibility failure is a rollback signal. If schema has already changed incompatibly, do not blindly roll back binaries. Plan forward repair or tested data restoration, accounting for writes since backup. Use migration ownership to prevent every replica racing to apply DDL.
Gate promotion
public class Main { static boolean promote(boolean ready,int success,int total){if(total<=0||success<0||success>total)throw new IllegalArgumentException();return ready&&100L*success>=99L*total;} public static void main(String[] args) { System.out.println(promote(true,98,100)); System.out.println(promote(true,99,100)); }}Expected output:
falsetrueA fictional threshold of 99% needs sufficient sample size and other checks in production.
Preserve previous artifact identity
import java.util.List;public class Main {
public static void main(String[] args) { var history=List.of("release-A","release-B"); System.out.println(history.get(history.size()-2)); }}Expected output:
release-AA release ledger can identify the previous artifact; an actual rollback requires verified digest and compatibility.
Common mistakes
Do not equate rollback with data recovery, remove a column while old code still depends on it, or assume an unavailable surge slot will appear. Do not execute kubectl against a shared or production cluster during this lab.
Practice
Check whether an old release accepting schemas 3 to 4 can run after schema 5. Print false. Explain why binary rollback must be blocked.
Expected output:
falseCompare with the manual review criteria.
Further reading: Deployments · Probes. Independent editorial review remains pending.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Deployment rollback — knowledge check
Container deployment and operations reasoning.
What can rolling updates require?
Does rollout undo restore database contents?
When should destructive schema cleanup occur?
Does progressDeadlineSeconds automatically roll back?
What is a safer rollback target?