Overview and What You Will Learn
A rollback returns production to the last known-good version after a bad deployment. The fastest options are flipping a feature flag, running kubectl rollout undo, or reverting the commit in your GitOps config repository. Automated rollback in Argo Rollouts goes further by aborting a release the moment a metric crosses a threshold.
Rolling back application code is nearly free, since the old image still exists. Rolling back a database change is the hard part, so this topic also covers how to design migrations that are safe to leave in place.
By the end of this topic you will be able to:
- Choose between rollback, flag flip, and roll-forward using a decision flow
- Use
kubectl rollout undoand Helm rollback in an emergency - Roll back through Git with Argo CD without fighting self-heal
- Configure Argo Rollouts to abort and revert automatically on bad metrics
- Design database migrations that do not block a rollback
- Write and rehearse an incident rollback runbook
Why This Matters in Production
Recovery time is a major driver of how much damage a bad release does. A team that detects a failure and reverts within minutes has an incident that barely registers, while a team that must find the right person and recall a manual sequence can turn the same defect into a long outage. For payment and trading systems, such as those run by Razorpay or Zerodha, every extra minute of failure is directly visible to customers.
Rollback is also a process, not just a command. Missing permissions, a pruned revision history, or a GitOps agent that undoes your fix are all problems you want to find during a rehearsal, not at 3am during an incident.
Common MistakeWorking out the rollback procedure during the incident. Discover that
kubectl rollout undois blocked by RBAC, or that the revision history was pruned, in a rehearsal.
Core Principles
Pick the fastest safe option by asking a few questions in order. Feature flags are fastest, schema changes need extra care, and the delivery method decides which command is correct.
kubectl rollout undo: The Emergency Button
kubectl rollout undo switches a Deployment back to its previous ReplicaSet directly in the cluster. It is fast and needs no Git access. It only reverts the Pod template, so changes to ConfigMaps, Services, replica counts, or other resources are not undone.
kubectl rollout undo deployment/order-gateway -n order-gateway-prodkubectl rollout status deployment/order-gateway -n order-gateway-prodBecause it changes the cluster without changing Git, it creates drift. If a GitOps agent with self-heal watches this Deployment, it will restore the broken version on its next reconcile unless you also revert in Git.
Security
kubectl rollout undoneeds write access to the cluster. If your normal path is GitOps-only, decide in advance who holds emergency credentials and how that access is granted and audited.
Helm Rollback
If a release is managed with Helm, roll back to a previous release revision, which restores all of the chart's resources and not only the Pod template.
helm history order-gateway -n order-gateway-prodhelm rollback order-gateway 14 -n order-gateway-prod --waitArgo CD Rollback: Revert in Git
The GitOps-native rollback reverts the bad commit in the config repository and lets the existing sync apply it. This agrees with how the change was deployed, so self-heal does not undo it. Use a pull request if the branch is protected, and add -m 1 when reverting a merge commit.
cd config-repogit switch -c revert-order-gateway-1-8-2git revert <bad-commit-sha> --no-edit # add -m 1 for a merge commitgit push -u origin revert-order-gateway-1-8-2 argocd app get order-gateway-production --refreshArgo CD can also sync to a specific earlier revision, which is useful for a temporary fix:
argocd app sync order-gateway-production --revision <previous-good-sha>RememberWith automated sync enabled, a manual sync to an older revision is overwritten at the next reconcile, and
argocd app rollbackis refused entirely. Either disable auto-sync during the incident, or make the revert in Git so the desired state itself changes.
TipPrefer
git revertovergit reset --hardon a config repository. A revert adds an auditable commit and works with branch protection, while a hard reset rewrites history.
Argo Rollouts: Automated Rollback on Metrics
With a canary strategy and an analysis step, Argo Rollouts queries a metrics provider during the release and aborts and reverts without a human if the result is bad. This is the fastest path because it starts the moment the threshold is crossed.
apiVersion: argoproj.io/v1alpha1kind: AnalysisTemplatemetadata: name: error-rate-checkspec: args: - name: service-name metrics: - name: error-rate interval: 1m count: 5 failureLimit: 1 # one bad reading aborts the rollout successCondition: result[0] < 0.02 provider: prometheus: address: http://prometheus.monitoring.svc:9090 query: | sum(rate(http_requests_total{service="{{args.service-name}}",status=~"5.."}[2m])) / sum(rate(http_requests_total{service="{{args.service-name}}"}[2m]))apiVersion: argoproj.io/v1alpha1kind: Rolloutmetadata: name: order-gateway namespace: order-gateway-prodspec: replicas: 6 selector: matchLabels: app: order-gateway strategy: canary: steps: - setWeight: 10 - analysis: templates: - templateName: error-rate-check args: - name: service-name value: order-gateway - setWeight: 50 - pause: { duration: 5m } template: metadata: labels: app: order-gateway spec: containers: - name: order-gateway image: 123456789012.dkr.ecr.ap-south-1.amazonaws.com/order-gateway:1.8.2The Hard Problem: Database Migrations
Application rollback is close to free because the old image still exists. Schema changes are not symmetric: a migration that drops a column cannot be undone without losing data written in the meantime. Rolling back the app and rolling back the database are separate decisions.
The standard mitigation is the expand and contract pattern, so no single deploy leaves the system in a state the old code cannot handle:
- Expand: add the new column as nullable, or add a new table, without removing anything.
- Dual write: deploy code that writes to both old and new, and backfill existing rows.
- Switch reads: move reads to the new column once the data is complete.
- Contract: drop the old column in a later, separate release, after the new path has run safely for a while.
If a migration truly cannot be made backward compatible, write and review its rollback plan before the migration runs.
Feature Flags: The Fastest Rollback
If the risky change is behind a flag, rollback is switching it off. There is no deployment and no pipeline run, and the change often reaches every instance within seconds. This is why high-risk changes are often shipped dark, with the flag off by default, and enabled gradually after the code is already deployed.
Rollback or Roll Forward
- Roll back when the previous version is known good and the fix is not ready.
- Roll forward when undoing would require reversing an unsafe schema change, and a verified fix is faster and safer than reasoning about the data.
- Flip the flag when the problem is contained inside a flagged feature.
Detailed Step-by-Step Practical Lab
This lab builds and rehearses a rollback runbook for an order-gateway service. Run it in staging first.
Step 1 - Check How Many Revisions You Can Roll Back To
revisionHistoryLimit controls how many old ReplicaSets Kubernetes keeps, and the default is 10. If it is set too low, an emergency undo has nothing useful to revert to.
kubectl rollout history deployment/order-gateway -n order-gateway-staging # Inspect what a specific revision containedkubectl rollout history deployment/order-gateway -n order-gateway-staging --revision=3Step 2 - Rehearse kubectl rollout undo in Staging
Deploy a deliberately broken image, wait for the rollout to fail, then undo it, timing the whole sequence.
kubectl -n order-gateway-staging set image deployment/order-gateway \ order-gateway=123456789012.dkr.ecr.ap-south-1.amazonaws.com/order-gateway:does-not-exist kubectl rollout status deployment/order-gateway -n order-gateway-staging --timeout=60s \ || kubectl rollout undo deployment/order-gateway -n order-gateway-staging kubectl rollout status deployment/order-gateway -n order-gateway-stagingkubectl get pods -n order-gateway-stagingTo return to a specific revision instead of the previous one, use kubectl rollout undo deployment/order-gateway --to-revision=3 -n order-gateway-staging.
Step 3 - Rehearse the Git Revert Path
Confirm that a revert commit actually triggers a sync and the cluster converges to the earlier state.
cd config-repogit revert HEAD --no-edit && git push origin mainargocd app get order-gateway-staging --refreshargocd app wait order-gateway-staging --health --timeout 120Step 4 - Verify the Automated Rollback Triggers
Apply the Rollout and AnalysisTemplate from Core Principles to staging. Release an image that returns errors above 2 percent, and confirm the rollout aborts and returns to the stable version without anyone running a command.
kubectl argo rollouts get rollout order-gateway -n order-gateway-staging --watch # Manual controls if you need themkubectl argo rollouts abort order-gateway -n order-gateway-stagingkubectl argo rollouts undo order-gateway -n order-gateway-stagingkubectl describe analysisrun -n order-gateway-stagingStep 5 - Attach a Rollback Note to Every Migration
Review rollback safety alongside the migration in the pull request, using a short template.
Migration: add_kyc_status_columnForward: add nullable column, backfill in batches, default applied by appRollback-safe: yes, old code ignores the columnRollback action if needed: none, no app rollback dependencyContract step (drop old column): scheduled for a later releaseStep 6 - Write the Incident Rollback Runbook
Store this where the on-call engineer can find it, and rehearse it on a schedule.
1. Confirm the suspected deployment and commit2. Behind a feature flag? Flip it off first3. GitOps managed: revert the config repo commit and watch the sync4. If urgent and sync is too slow: kubectl rollout undo, then also revert in Git so self-heal does not restore the bad version5. Schema change in the deploy? Check the migration's rollback note6. Verify health: pods ready, error rate and latency back to baseline7. Record the timeline, the path used, and the time to recoverProduction Best Practices & Common Pitfalls
- Keep enough history. Set
revisionHistoryLimithigh enough that an emergency undo always has somewhere to go. - Pair emergency changes with Git. If you undo directly in the cluster, revert in Git too, or self-heal restores the broken version.
- Review rollback safety at pull request time. Every migration should state whether it is safe to leave in place.
- Rehearse on a schedule. A procedure nobody has run is a procedure whose timing you cannot trust.
- Ship risky changes behind flags. Off by default gives you the fastest rollback before you need it.
- Verify after rolling back. A rollback is only done when health checks and error rates return to normal.
- Keep old images. Set ECR lifecycle rules that retain the recent tags you might need to roll back to.
Common MistakeRolling back the application while the database change stays in place without checking compatibility. If the old code cannot work with the new schema, the rollback itself becomes an outage.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
kubectl rollout history deployment/<name> |
List available revisions |
kubectl rollout undo deployment/<name> |
Revert to the previous revision |
kubectl rollout undo deployment/<name> --to-revision=N |
Revert to a specific revision |
helm rollback <release> <revision> |
Roll back a Helm release |
argocd app sync <app> --revision <sha> |
Sync to a specific Git revision |
kubectl argo rollouts abort <name> |
Stop a progressing rollout |
kubectl argo rollouts undo <name> |
Return a rollout to the previous version |
| Symptom | Likely Cause | Fix |
|---|---|---|
| Undo has nothing to revert to | revisionHistoryLimit too low |
Raise it before the next incident |
| Rollback keeps getting reverted | Self-heal is active | Revert in Git, or pause auto-sync |
argocd app rollback refused |
Auto-sync is enabled | Use git revert or disable auto-sync |
| Errors continue after rollback | Schema change not addressed | Check the migration's rollback note |
| Automated rollback never fires | Analysis query returns no data | Run kubectl describe analysisrun and fix the query |
helm rollback fails |
Revision number is wrong | Check helm history for valid revisions |