10 Deployment Rollback Strategies With Commands

10 deployment rollback strategies with commands: kubectl rollout undo, helm rollback, GitOps revert, canary abort, ECS circuit breaker, expand-contract.

Dec 22, 2025 - 11:58
Nov 10, 2026 - 12:28
 0  197
10 Deployment Rollback Strategies With Commands

A deployment rollback returns production to the last known good version when a release fails. The ten strategies that matter are Kubernetes rollout undo, Helm rollback, GitOps revert, blue-green switchback, canary abort, feature flag kill switches, platform auto-rollback (CodeDeploy, ECS), database expand and contract, infrastructure revert, and roll forward with a fix.

This guide shows when to use each one, the exact command or setting, and what can go wrong. It is about getting back to safety. For how releases are rolled out in the first place, see our companion post on CI/CD deployment rollout types and the CI/CD pillar, CI/CD pipeline examples from big tech companies. Commands were checked against the official Kubernetes, Helm, Argo CD, Argo Rollouts and AWS documentation in November 2026.

Key takeaways

  • Decide before a release how you will roll it back, and test that path in staging. A rollback you have never run is a guess.
  • Application code is easy to roll back. Database schema changes and external side effects (emails sent, payments taken) are not, so design them to be backward compatible.
  • In GitOps, the rollback is a Git revert. Changing the cluster directly gets overwritten by the next sync.
  • Automate the trigger: let error rate and latency metrics abort a canary or roll back a deployment without waiting for a human.
  • Rolling forward with a small fix is often safer than rolling back when data has already changed shape.

Rollback strategies compared

#StrategyWhere it appliesSpeedMain risk
1kubectl rollout undoKubernetes DeploymentsMinutesCluster drifts from Git or Helm state
2helm rollbackHelm releasesMinutesCRDs and hooks are not reverted the way you expect
3GitOps revertArgo CD, FluxMinutes (sync interval)Slow if sync interval is long
4Blue-green switchbackLoad balancer or service selectorSecondsDouble infrastructure cost while both run
5Canary abortArgo Rollouts, Flagger, service meshSecondsOnly a slice of users saw the failure, so detection needs good metrics
6Feature flag kill switchApplication codeSecondsFlag debt if old flags are not removed
7Platform auto-rollbackAWS CodeDeploy, Amazon ECSMinutesAlarm thresholds tuned too loose or too tight
8Expand and contract migrationsRelational databasesPlanned over releasesDiscipline needed across several deploys
9Infrastructure revertTerraform, CloudFormationMinutes to hoursDestroyed resources and data do not come back
10Roll forwardAnyDepends on pipeline speedPressure to skip tests during an incident

The 10 strategies

1. Kubernetes rollout undo

Kubernetes keeps old ReplicaSets for each Deployment (10 by default, set by revisionHistoryLimit). Undoing a rollout scales the previous ReplicaSet back up and the new one down, using the Deployment's rolling update settings.

# See history and what changed in each revision
kubectl rollout history deployment/checkout -n shop
kubectl rollout history deployment/checkout -n shop --revision=7

# Go back one revision, or to a specific one
kubectl rollout undo deployment/checkout -n shop
kubectl rollout undo deployment/checkout -n shop --to-revision=7

# Watch until the rollback completes
kubectl rollout status deployment/checkout -n shop

Set kubernetes.io/change-cause annotations so the history tells you which image or ticket each revision belongs to. The catch: if the Deployment is managed by Helm or a GitOps tool, an undo here makes the cluster disagree with its source of truth, and the next pipeline run or sync puts the bad version back. Use it as an emergency step and then fix the source. See the Kubernetes Deployment rollback docs.

2. Helm rollback

Helm stores every release revision as a Secret in the release namespace. helm rollback re-applies the manifests from an earlier revision and records the rollback as a new revision.

helm history checkout -n shop
helm rollback checkout 12 -n shop --wait --timeout 5m

Omitting the revision number rolls back to the previous release. Helm does not upgrade or delete CustomResourceDefinitions placed in a chart's crds/ directory, so CRD changes need their own plan. Hooks (for example a migration job) run again only if they are defined for rollback events. Using helm upgrade --atomic (renamed --rollback-on-failure in Helm 4) rolls back automatically when an upgrade fails. See helm rollback.

3. GitOps revert with Argo CD or Flux

In GitOps, Git is the record of what should run. The cleanest rollback is a revert commit that restores the previous image tag or chart version; the controller syncs it like any other change, and the history shows who rolled back and why.

git revert --no-edit 4f2c9ab
git push origin main
# Argo CD: trigger an immediate sync instead of waiting for the poll
argocd app sync checkout

Argo CD also has argocd app rollback APPNAME [ID], which redeploys an earlier entry from the application's history. Argo CD does not allow this while automated sync is enabled, because auto-sync would immediately move the app back to the Git state. Disable auto-sync, roll back, then revert in Git and re-enable it. With Flux, the equivalent emergency move is flux suspend kustomization <name> while you fix Git. See the argocd app rollback reference and our GitOps explainer.

4. Blue-green switchback

Blue-green runs the old (blue) and new (green) versions side by side and moves traffic by changing a load balancer target or a Kubernetes Service selector. Rolling back means pointing traffic at blue again, which takes seconds because blue is still running and warm.

# Service selector switch back to the previous version
kubectl patch service checkout -n shop \
  -p '{"spec":{"selector":{"app":"checkout","version":"blue"}}}'

Keep blue running until green has passed a full traffic cycle (including peak hours and scheduled jobs). Both versions must work with the same database schema, which is why strategy 8 matters. Our post on Kubernetes deployment strategies has full blue-green YAML.

5. Canary abort

A canary sends a small share of traffic to the new version, checks metrics, then increases the share step by step. If metrics go bad, aborting sends all traffic back to the stable version. Argo Rollouts and Flagger automate this with analysis based on Prometheus, Datadog, New Relic or other providers.

# Argo Rollouts: stop the canary and return traffic to stable
kubectl argo rollouts abort checkout -n shop

# Roll the spec back to the previous revision
kubectl argo rollouts undo checkout -n shop

An AnalysisTemplate makes the abort automatic. This one fails the rollout if the success rate falls below 99%:

apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: success-rate
spec:
  metrics:
  - name: success-rate
    interval: 1m
    failureLimit: 2
    successCondition: result[0] >= 0.99
    provider:
      prometheus:
        address: http://prometheus.monitoring:9090
        query: |
          sum(rate(http_requests_total{app="checkout",code!~"5.."}[2m]))
          /
          sum(rate(http_requests_total{app="checkout"}[2m]))

See the Argo Rollouts analysis docs.

6. Feature flag kill switch

Feature flags separate deploying code from releasing a feature. New behaviour ships turned off, then gets enabled for a percentage of users. If it misbehaves, turning the flag off is the rollback: no build, no deploy, effective in seconds.

Flags only help for changes that were put behind a flag, and old flags left in code become technical debt. Give every flag an owner and a removal date. OpenFeature, a CNCF project, provides a vendor-neutral flag API. Our list of feature flag tools compares the main products.

7. Platform auto-rollback: AWS CodeDeploy and Amazon ECS

Managed deployment services can roll back without a human. AWS CodeDeploy can roll back automatically when a deployment fails or when a CloudWatch alarm you attach goes into ALARM state. In the deployment group:

"autoRollbackConfiguration": {
  "enabled": true,
  "events": ["DEPLOYMENT_FAILURE", "DEPLOYMENT_STOP_ON_ALARM"]
},
"alarmConfiguration": {
  "enabled": true,
  "alarms": [{ "name": "checkout-5xx-high" }]
}

Amazon ECS rolling deployments have a deployment circuit breaker. With rollback enabled, ECS returns to the last completed deployment if tasks keep failing to reach a steady state:

"deploymentConfiguration": {
  "deploymentCircuitBreaker": { "enable": true, "rollback": true }
}

ECS can also roll back on CloudWatch alarms. See CodeDeploy rollbacks and the ECS deployment circuit breaker.

8. Database expand and contract

You cannot roll back a dropped column. The expand and contract approach (also called parallel change) makes every schema change backward compatible so application rollbacks stay safe:

  1. Expand: add the new column or table. Old code ignores it.
  2. Deploy code that writes to both old and new structures and reads from the old one.
  3. Backfill existing rows.
  4. Deploy code that reads from the new structure.
  5. Contract: once no running version uses the old structure, remove it in a later release.

At every step, the previous application version still works, so rolling back the code never needs a schema rollback. Migration tools such as Flyway and Liquibase version these steps; treat "down" migrations as a last resort because they often lose data. Take a backup or snapshot before any destructive step.

9. Infrastructure revert

Terraform has no rollback command. To undo a change, revert the configuration in Git and run terraform plan and terraform apply again; Terraform then moves real resources back to match. Read the plan carefully, because reverting can replace resources instead of updating them, and anything destroyed (a database, a disk) does not come back with its data.

git revert --no-edit a91c3de
terraform plan -out=rollback.tfplan
terraform apply rollback.tfplan

Protect stateful resources with lifecycle { prevent_destroy = true } and keep state versioning on (for example S3 bucket versioning). AWS CloudFormation, by contrast, rolls back a failed stack update automatically to the last stable state. See the Terraform lifecycle docs.

10. Roll forward with a fix

Sometimes going back is worse than going forward: the new version has already migrated data, sent messages in a new format, or the bug is a one-line config error. Rolling forward means shipping a small fix through the normal pipeline. It only works if the pipeline is fast and trusted, so invest in build speed and keep the emergency path the same as the normal path, with the same tests.

Write the decision rule down in advance, for example: roll back if the cause is unknown or the fix is more than a small change; roll forward if the cause is known and the fix is trivial.

Building a rollback runbook

StepWhat to do
DetectAlerts on error rate, latency and saturation tied to SLOs; deployment markers in dashboards
DecideOne named person makes the call; use the roll back or roll forward rule agreed in advance
ActRun the documented command for this service (from the list above)
VerifyCheck health endpoints, error rate and key user journeys; see our post-deployment validation steps
ReconcileMake Git, Helm and pipeline state match what is running
LearnBlameless review: why tests missed it, and which check would catch it next time

Track how often you roll back. DORA's change failure rate and failed deployment recovery time measure exactly this, as described in the DORA metrics guide. Automated rollback is one form of self-healing in DevOps systems.

To practise Kubernetes rollouts and rollbacks on real clusters, see the CKA training or the full DevOps training in Pune, in Kharadi or live online.

Rollback anti-patterns to avoid

  • Rebuilding the old version from source during an incident. Builds are not always reproducible; redeploy the exact artifact or image digest that ran before.
  • Using the latest tag. If every release is latest, there is no previous version to return to. Tag with versions or commit SHAs and deploy by digest.
  • Fixing the cluster by hand and forgetting the source. Manual kubectl edit changes vanish at the next sync or pipeline run, and the bug comes back.
  • Shipping schema and code changes together in one irreversible step. Split them so each can be undone, as in strategy 8.
  • Keeping too little history. A revisionHistoryLimit of 0 or a registry lifecycle rule that deletes recent images can leave nothing to roll back to.
  • Never rehearsing. Run a rollback in staging as part of every release process, or schedule game days where the team practises it.

Official references

Frequently asked questions

What is a deployment rollback?

A rollback returns a system to a previous known good version after a release causes problems. It can mean redeploying the old image, switching traffic back to the old environment, or turning off a feature flag.

How do I roll back a Kubernetes deployment?

Run kubectl rollout undo deployment/NAME to go back one revision, or add --to-revision=N for a specific one. Check kubectl rollout history first. If Helm or GitOps manages the Deployment, also fix the source, or the bad version returns on the next sync.

Can Argo CD roll back automatically?

Argo CD itself rolls back through Git reverts or the argocd app rollback command, which is blocked while auto-sync is enabled. For automatic metric-based rollback, use Argo Rollouts or Flagger alongside Argo CD.

How do you roll back a database change?

Avoid needing to. Use expand and contract migrations so each schema change works with both the old and new application versions. Then rolling back the application never requires undoing the schema. Keep backups for destructive steps.

Does Terraform have a rollback command?

No. Revert the configuration in version control and run terraform plan and apply again. Review the plan closely, because some reverts replace resources, and destroyed data is not restored.

When should I roll forward instead of rolling back?

Roll forward when the cause is known, the fix is small, and rolling back would be risky, for example after data has been migrated to a new format. Roll back when the cause is unclear.

What is the fastest rollback strategy?

Feature flag kill switches and blue-green traffic switches take seconds, because the old code path is already running. Redeploying an old image takes longer because new pods or instances must start.

How do I know when to trigger a rollback?

Define thresholds before the release, such as error rate above 1% or p95 latency 20% above baseline for five minutes, and wire them into alarms or canary analysis so rollback can start automatically.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.