Prompt
Kubernetes rollout rollback best practice
Latest observation
Here are solid best practices for Kubernetes rollout rollback:
1) Prefer controlled rollouts over instant changes
Use Deployment updates with:
- RollingUpdate strategy
- conservative values for:
maxUnavailablemaxSurge
This reduces blast radius and makes rollback safer.
2) Make rollbacks easy by keeping revisions
Kubernetes Deployments keep rollout history. You can rollback with:
kubectl rollout undo deployment/<name>
Or to a specific revision:
kubectl rollout undo deployment/<name> --to-revision=<n>
3) Use health checks properly
Define:
readinessProbelivenessProbe- optionally
startupProbe
A bad rollout should stop receiving traffic quickly if readiness fails.
4) Verify before promoting
Before considering a rollout successful:
- check pod readiness
- inspect events/logs
- verify app metrics, error rates, latency
- confirm downstream dependencies
Useful commands:
kubectl rollout status deployment/<name>
kubectl describe deployment/<name>
kubectl get pods -w
5) Automate rollback on failure
Use CI/CD or deployment tooling to rollback when:
- rollout times out
- readiness drops
- SLOs degrade
- error rate spikes
Canary or progressive delivery tools help a lot here.
6) Use canary or blue-green for critical workloads
For production systems, a safer pattern than direct rolling updates is:
- Canary: shift a small percentage of traffic first
- Blue/Green: keep old version ready and switch traffic
These make rollback much faster and less risky.
7) Keep backward compatibility
New versions should ideally be compatible with:
- existing DB schema
- older clients
- in-flight requests
- shared message formats
If rollback happens, incompatibilities can break recovery.
8) Manage database migrations carefully
This is a common rollback trap. Best practice:
- use expand/contract migrations
- avoid destructive schema changes in the same deploy
- make migrations reversible when possible
9) Tag and version images immutably
Use immutable image tags or digests, not latest.
Example:
image: myapp@sha256:...
This ensures rollback goes to a known-good artifact.
10) Document a rollback runbook
Have a simple runbook with:
- how to identify bad rollout
- rollback command
- validation steps after rollback
- who to notify
Typical rollback flow
- Detect issue via metrics/alerts
- Pause rollout if needed:
kubectl rollout pause deployment/<name> - Roll back:
kubectl rollout undo deployment/<name> - Verify stability:
kubectl rollout status deployment/<name> - Investigate root cause before re-deploying
Practical recommendation
For most teams:
- use rolling updates + probes + automated health checks
- for high-risk services, use canary or blue/green
- ensure schema compatibility and immutable image versions
If you want, I can also give you:
- a production-ready deployment YAML with rollback-friendly settings, or
- a step-by-step rollback runbook.
Brands