An arrow showing a kubectl rollout undo command rolling back a Kubernetes deployment.

How to `kubectl rollout undo deployment` Safely

Learn how to use `kubectl rollout undo deployment` safely, with step-by-step guidance, best practices, and troubleshooting tips for reliable Kubernetes rollbacks.

Michael Guarino
Michael Guarino

In modern infrastructure management, GitOps provides a declarative model where your repository is the single source of truth. However, when an incident occurs, the immediate, imperative fix is often the kubectl rollout undo deployment command. This creates a direct conflict: you've modified the live state of your cluster, causing it to drift from the configuration defined in Git. This guide explores that tension. We'll cover the mechanics of the command itself, but more importantly, we will discuss its limitations within an automated, declarative workflow and explain why a proper rollback strategy must be integrated with your version control system to maintain consistency and avoid having your manual fixes overwritten.

Unified Cloud Orchestration for Kubernetes

Manage Kubernetes at scale through a single, enterprise-ready platform.

GitOps Deployment
Secure Dashboards
Infrastructure-as-Code
Book a demo

Key takeaways:

  • Rollbacks require manual intervention: Kubernetes identifies a failed deployment but does not automatically revert it. Your team is responsible for initiating the recovery process with kubectl rollout undo, making it a critical but reactive tool for incident response.
  • Use revision history for targeted recovery: Before acting, inspect a deployment's past with kubectl rollout history. This allows you to use the --to-revision flag to restore a specific, known-good version instead of just the immediately previous one.
  • Prioritize GitOps for reliable rollbacks at scale: Imperative commands like kubectl rollout undo create state drift and conflict with declarative workflows. The best practice is to revert the problematic commit in Git, letting a platform like Plural apply the change consistently across your entire fleet.

What Is kubectl rollout undo?

kubectl rollout undo is an imperative Kubernetes command used to roll back a workload to a previously deployed revision. It’s typically used during incident response to quickly restore a known-good state when a rollout introduces regressions such as failed pods, degraded latency, or misconfiguration.

How the Command Works

Kubernetes tracks rollout history via underlying ReplicaSets (for Deployments) or controller-managed revisions (for DaemonSets and StatefulSets). Each update creates a new revision. The undo operation re-targets the controller to a prior revision and adjusts the managed pods accordingly.

Common usage:

Roll back to the previous revision:

kubectl rollout undo deployment/webapp

Roll back to a specific revision:

kubectl rollout undo deployment/webapp --to-revision=3

Inspect rollout history:

kubectl rollout history deployment/webapp

This mechanism is consistent across supported workload types, including Deployments, DaemonSets, and StatefulSets.

What a “Revision” Represents

A revision is a snapshot of the workload’s pod template (spec.template) at a point in time. For Deployments, each revision corresponds to a ReplicaSet with a unique hash derived from that template. Rollback works by promoting an older ReplicaSet back to active status.

Scope and Limitations

  • Cluster-only change: The rollback mutates live cluster state only. It does not update manifests in Git or any external source of truth.
  • Dependent on history: Rollback availability depends on retained revision history (revisionHistoryLimit).
  • No automatic rollback: Kubernetes does not revert failed rollouts by default. If a rollout exceeds progressDeadlineSeconds or stalls, it remains in a failed state until acted upon.
  • Not a full “time machine”: Only fields captured in the pod template are reverted; external dependencies (e.g., ConfigMaps updated out-of-band) may still cause issues.

Operational Considerations

  • Use it for fast mitigation, not as a long-term state change.
  • Pair with monitoring/alerting to detect failed rollouts quickly.
  • In GitOps setups, ensure you reconcile the rollback in Git or temporarily pause reconciliation to avoid the controller reapplying the faulty version.

Breaking Down kubectl rollout undo

kubectl rollout undo is an imperative control used to revert Kubernetes workloads (Deployments, DaemonSets, StatefulSets) to a prior revision. It’s optimized for fast recovery: the controller switches back to an earlier pod template and performs a rolling update to replace the current pods with the previous, stable version.

Mechanics

For Deployments, each change to spec.template creates a new ReplicaSet (revision). The undo operation re-targets the Deployment to a selected revision:

  • The controller scales down the current ReplicaSet.
  • It scales up the target (older) ReplicaSet.
  • The rollout strategy (e.g., RollingUpdate) governs surge/unavailable limits, so the transition is incremental and typically low-downtime.

For DaemonSets and StatefulSets, the controller applies the same principle using their respective revision tracking.

Key Options and Flags

Roll back to the previous revision:

kubectl rollout undo deployment/webapp

Roll back to a specific revision:

kubectl rollout undo daemonset/logging-agent --to-revision=3

Preview the server-side outcome (no mutation):

kubectl rollout undo deployment/webapp --dry-run=server -o yaml

Requirements:

  • You must specify the resource (deployment/<name>, daemonset/<name>, statefulset/<name>).
  • The target revision must exist within the retained history (revisionHistoryLimit).

Inspecting Rollout History

Before rolling back, enumerate revisions and identify the correct target:

List revisions:

kubectl rollout history deployment/api-server

Inspect a specific revision:

kubectl rollout history deployment/api-server --revision=3

The history output includes revision numbers and any recorded change cause.

Recording Change Causes

Annotate changes to make history actionable. Use kubernetes.io/change-cause so each revision has context:

kubectl annotate deployment/api-server \
  kubernetes.io/change-cause="Upgrade image to v1.4.2"

Best practice is to set this annotation at deploy time (e.g., via your CI/CD or manifests) so every revision is traceable.

Operational Notes

  • Scope: The rollback affects only live cluster state; it does not update your Git source of truth.
  • Determinism: Ensure images are immutable (no :latest) to make rollbacks predictable.
  • Failure handling: Kubernetes won’t auto-rollback on stalled rollouts; you must trigger it (or use higher-level tooling).
  • Safety: Use --dry-run=server and review history before selecting a revision to avoid reverting to a broken state.

When Should You Roll Back a Kubernetes Deployment?

A rollback is an incident-response primitive for restoring a known-good revision when a release degrades correctness, availability, or performance. The decision should be signal-driven and fast, with the objective of minimizing MTTR while preserving system integrity. In practice, you correlate deployment timestamps with SLO/SLA violations surfaced by observability. Tools like Plural centralize health, metrics, and rollout context across clusters, making that correlation explicit.

Responding to Failed Deployments and Application Errors

Trigger an immediate rollback when the rollout is functionally broken:

  • Pods in CrashLoopBackOff, failing readiness/liveness probes, or ImagePullBackOff.
  • Rollout stalls past progressDeadlineSeconds (Kubernetes marks it failed but does not auto-revert).
  • Post-deploy spike in application errors (e.g., elevated 5xx rates) or failed critical paths.

Action: revert to the last stable revision to restore service, then debug offline. Waiting for self-recovery is usually counterproductive once hard failure signals are present.

Addressing Performance Degradation

Roll back on sustained SLO regression even if the rollout “succeeds”:

  • Increased p95/p99 latency, reduced throughput.
  • Elevated CPU/memory causing throttling or eviction pressure.
  • Rising but non-fatal error rates.

Key is correlation: if degradation aligns with the rollout window, revert first, investigate second. This limits blast radius and buys time for root-cause analysis without user impact.

Correcting Configuration Mistakes

Many regressions are configuration-driven and won’t crash the app:

  • Incorrect ConfigMap/Secret values, environment variables, or feature flags.
  • Misrouted dependencies (e.g., wrong database/endpoint).
  • Invalid toggles that disable critical flows.

Because these are embedded in the workload’s revision (pod template), a rollback restores the previous, working configuration immediately, reducing risk of data inconsistency or user-facing faults.

Practical Guardrails

  • Define rollback thresholds: codify SLO breach conditions that auto-trigger rollback via your delivery tooling.
  • Ensure observability coverage: metrics, logs, and traces must be sufficient to attribute regressions to a specific release.
  • Prefer Git-driven reverts in GitOps: if you use controllers, commit a revert (or pause reconciliation before an imperative rollback) so the cluster doesn’t drift from source of truth.
  • Use immutable artifacts: pin image digests/tags to guarantee deterministic reversions.

How to Roll Back to the Previous Deployment

A rollback reverts a workload to its last known-good revision to restore service quickly. The imperative path uses kubectl rollout undo, which updates the Deployment’s pod template to a prior revision and triggers a new rollout. In multi-cluster environments, you need centralized visibility to ensure consistency—platforms like Plural aggregate rollout status and health signals across clusters so you can validate outcomes in one place.

Step-by-Step Rollback

Roll back a Deployment to its immediate previous revision:

kubectl rollout undo deployment/api-service

What happens under the hood:

  • The Deployment is re-pointed to the previous ReplicaSet (revision).
  • Kubernetes performs a rolling update using that older pod template.
  • New pods from the stable revision are created while current pods are terminated, respecting surge/unavailable constraints.

For targeted recovery, you can select a specific revision:

kubectl rollout undo deployment/api-service --to-revision=3

Verifying a Successful Rollback

Don’t stop at triggering the undo—verify convergence and health:

Watch rollout status

kubectl rollout status deployment/api-service

Confirms the controller completed the rollout without stalls.

Confirm active revision

kubectl rollout history deployment/api-service

Ensure the intended revision is now active.

Inspect pods

kubectl get pods -l app=api-service -o wide

Validate that pods from the previous (stable) template are running and old pods are terminated.

Check application health

  • Error rates (e.g., 5xx), latency (p95/p99), and resource metrics should return to baseline.
  • Logs should no longer show the regression introduced by the bad release.

How to Roll Back to a Specific Revision

Rolling back to the previous revision isn’t always sufficient—regressions can originate several releases back. Kubernetes retains a revisioned history of each workload, allowing you to target an exact, known-good state. This is essential when multiple successive deploys are suspect or when you need to restore a specific configuration snapshot.

Using the --to-revision Flag

Target a specific revision with --to-revision. This bypasses the default “previous revision” behavior and instructs the controller to roll back to the exact version you specify.

kubectl rollout undo deployment/webapp-frontend --to-revision=3

What this does:

  • Re-points the Deployment to the ReplicaSet associated with revision 3.
  • Triggers a rolling update using that pod template.
  • Scales down current pods and scales up pods from the selected revision, respecting rollout strategy constraints.

Use this when:

  • Multiple recent revisions are faulty.
  • You’ve identified a stable baseline further back in history.
  • You need a deterministic revert to a specific image/config combination.

Finding the Correct Revision Number

Always inspect history before selecting a target:

kubectl rollout history deployment/webapp-frontend

For deeper inspection:

kubectl rollout history deployment/webapp-frontend --revision=3

The history output lists revision numbers and any recorded change causes. To make this reliable:

  • Record change causes (e.g., via kubernetes.io/change-cause annotations) during each deploy.
  • Avoid mutable tags (no :latest); use immutable tags/digests so revisions map to exact artifacts.

Operational Considerations

  • History retention: Ensure revisionHistoryLimit is high enough; otherwise, older revisions may be garbage-collected.
  • State completeness: Rollback restores the pod template; external changes (e.g., updated ConfigMaps not versioned in the template) may still affect behavior.
  • Verification: After rollback, confirm with:
kubectl rollout status deployment/webapp-frontend
kubectl get rs -l app=webapp-frontend

and validate application SLIs (errors, latency) return to baseline.

  • GitOps alignment: If using a reconciler, either pause it or commit an equivalent Git revert immediately to prevent drift and reapplication of a bad revision.

Limitations of kubectl rollout undo

kubectl rollout undo is effective for rapid, tactical mitigation, but it is not a complete rollback strategy for production-grade, automated environments. Its constraints show up in three areas: bounded history, incompatibility with GitOps reconciliation, and lack of automation. At scale, these gaps require a workflow where rollbacks are version-controlled, policy-driven, and observable—capabilities typically provided by platforms like Plural.

Revision History Constraints

Rollbacks depend on retained revisions:

  • Finite history: Controlled by .spec.revisionHistoryLimit (default: 10). Older ReplicaSets are garbage-collected.
  • Non-deterministic availability: If a target revision has been pruned, it’s unrecoverable via rollout undo.
  • Short-term utility: This makes the command reliable mainly for recent regressions, not long-tail issues.

Operational implication: treat revision history as a cache, not an archive. Long-term rollback fidelity must come from version control and immutable artifacts.

Conflicts with GitOps Workflows

In GitOps, Git is the source of truth and controllers continuously reconcile cluster state:

  • Imperative drift: rollout undo mutates live state outside Git.
  • Reconciliation overwrite: Controllers (e.g., Argo CD, Flux) will revert the cluster back to the Git-defined (possibly bad) version.
  • Audit gaps: The rollback isn’t captured as a reviewable, versioned change.

Correct pattern:

  • Preferred: git revert (or promote a known-good commit) → let the controller apply it.
  • Emergency: pause reconciliation → rollout undo → immediately commit the equivalent revert → resume reconciliation.

Lack of Automated Failure Response

Kubernetes does not auto-rollback on failed rollouts:

  • Stalled rollouts: Exceeding progressDeadlineSeconds marks the Deployment as failed but takes no corrective action.
  • Manual intervention required: Operators must detect the failure and trigger a rollback.
  • Higher MTTR risk: During incidents, this increases latency and the chance of human error.

Mitigations:

  • Progressive delivery (canary/blue-green) with automated analysis and rollback.
  • SLO-driven policies to trigger reverts based on metrics (error rate, latency).
  • Centralized observability and control (e.g., Plural) to correlate deploys with health signals and orchestrate consistent rollbacks across clusters.

Best Practices for Safe and Effective Rollbacks

Rollbacks should be engineered as a repeatable, low-risk operation—not an ad-hoc reaction. While kubectl rollout undo provides the primitive, reliability comes from validation, observability, and process discipline. At scale, platforms like Plural help standardize these practices across clusters with centralized visibility and policy-driven workflows.

Use Dry-Run to Validate the Action

Always preview before mutating live state:

kubectl rollout undo deployment/app --dry-run=server -o yaml
  • Confirms the target revision and request validity.
  • Surfaces API/validation errors without persisting changes.
  • Reduces operator error (wrong resource, wrong revision).

Treat this as a pre-flight check in your runbook.

Monitor Rollout Progress and Health

Triggering a rollback is only step one—verify convergence and service health:

kubectl rollout status deployment/app
  • Blocks until the controller reports a successful rollout or failure.
  • Relies on readiness/liveness probes to gate traffic and determine stability.

Augment with SLIs:

  • Error rate (e.g., 5xx), latency (p95/p99), saturation (CPU/memory).
  • Logs/traces to confirm the regression is gone.

Maintain High-Quality Deployment Annotations

Make revision history actionable:

kubectl annotate deployment/app \
  kubernetes.io/change-cause="Upgrade to v1.4.2; enable feature X"
  • Provides human-readable context in kubectl rollout history.
  • Speeds up correct revision selection under pressure.
  • Improves auditability and post-incident analysis.

Prefer setting this in CI/CD so every revision is annotated consistently.

Rehearse Rollbacks in Staging

Continuously test the rollback path:

  • Validate end-to-end: detection → decision → rollback → verification.
  • Catch environment drift (configs, secrets, quotas) early.
  • Expose edge cases (e.g., schema migrations, backward-incompatible changes).

Make rollback drills part of release readiness, not a one-off exercise.

Additional Guardrails

  • Immutable artifacts: Pin image digests/tags; avoid :latest for deterministic reversions.
  • Sufficient history: Set revisionHistoryLimit high enough for your risk window.
  • GitOps alignment: Prefer Git reverts; if you use rollout undo, pause reconciliation or backfill the change to Git immediately.
  • Progressive delivery: Use canary/blue-green with automated analysis to reduce the need for manual rollbacks.

Manage Rollbacks at Scale with Plural

While kubectl rollout undo is a powerful command for a single cluster, its effectiveness diminishes when you manage a fleet of Kubernetes clusters. Executing rollbacks manually across dozens or hundreds of environments is not only inefficient but also prone to error. A failed deployment in one cluster can have cascading effects, and without a unified management plane, coordinating a fleet-wide rollback becomes a significant operational burden. This is where managing your deployments through a centralized platform becomes critical.

Plural provides a single pane of glass for enterprise-grade Kubernetes fleet management, transforming how you handle deployments and rollbacks. By leveraging a GitOps-centric approach, Plural ensures that every change, including a rollback, is version-controlled, auditable, and consistently applied across your entire infrastructure. Instead of reacting to failures on a per-cluster basis, you can define and automate rollback strategies that scale with your organization. Plural’s architecture gives you the control and visibility needed to execute rollbacks confidently, minimizing downtime and maintaining system stability across all your environments.

Automate Rollback Workflows with GitOps

Manual rollbacks are a reactive measure. A more robust strategy involves automating the process within your CI/CD pipeline. With Plural, you can build this automation directly into your GitOps workflow. Instead of relying on scripts to check deployment health and trigger kubectl rollout undo, you can manage the application's desired state in Git. If a new deployment introduces issues, the rollback is as simple as reverting the commit and letting Plural’s GitOps engine synchronize the change across the target clusters. This approach ensures that your version control system remains the single source of truth for your cluster's state, making the entire process transparent and auditable.

Manage Deployments Across Your Fleet

Kubernetes natively retains old ReplicaSets, which makes reverting to a previous application version possible. However, tracking and managing these ReplicaSets across a distributed fleet is a complex task. Plural CD simplifies this by providing a unified control plane to manage deployments across any number of clusters, regardless of their location. Using a secure, agent-based architecture, Plural applies configuration changes consistently everywhere. When a rollback is necessary, you can initiate it from a central point, and Plural ensures the change is propagated correctly to every cluster in your fleet, guaranteeing consistency and reducing the risk of configuration drift.

Monitor Rollbacks from a Central Dashboard

Verifying a rollback's success often requires running kubectl commands on each affected cluster, a tedious and time-consuming process. Plural eliminates this friction with its embedded Kubernetes dashboard. This dashboard gives you a real-time, consolidated view of all your deployments and their rollout histories across your entire fleet. You can monitor the progress of a rollback, inspect pod statuses, and verify that the correct ReplicaSet is active, all from a single UI. This centralized visibility simplifies troubleshooting and confirms that your rollback was successful without requiring you to juggle multiple terminals or kubeconfigs.

Unified Cloud Orchestration for Kubernetes

Manage Kubernetes at scale through a single, enterprise-ready platform.

GitOps Deployment
Secure Dashboards
Infrastructure-as-Code
Book a demo

Frequently Asked Questions

Does Kubernetes automatically roll back a failed deployment? No, it does not. A common misconception is that Kubernetes will automatically revert a deployment if it fails to become healthy. If a deployment exceeds its progressDeadlineSeconds, it will be marked as failed, but it will remain in that broken state. It is up to an operator or an automated system to detect the failure and initiate a rollback command.

Will kubectl rollout undo cause downtime for my application? The command is designed to minimize downtime by using the same rolling update strategy as a regular deployment. Kubernetes gracefully terminates pods from the faulty version while creating new pods from the stable, older version. Your Service object ensures traffic is only directed to healthy, ready pods, so the transition should be seamless for users as long as your application has proper health checks configured.

Why shouldn't I use kubectl rollout undo if I'm using GitOps? Using kubectl rollout undo directly conflicts with the core principle of GitOps, where your Git repository is the single source of truth. The command changes the cluster's state imperatively, creating a drift between what's running and what's in your repository. Your GitOps controller will likely detect this mismatch and "fix" it by reapplying the faulty configuration from Git, effectively undoing your rollback. The correct GitOps approach is to revert the commit in your repository.

What happens if I need to roll back to a version from several weeks ago? Your ability to roll back is limited by the deployment's revision history. Kubernetes stores a finite number of old ReplicaSets, configured by the .spec.revisionHistoryLimit field, which defaults to 10. If the version you need to restore is older than what's saved in the history, you cannot use kubectl rollout undo to revert to it. This makes the command best suited for immediate, short-term fixes rather than long-term recovery.

How does a platform like Plural improve the rollback process? Plural integrates rollbacks into a controlled, GitOps-based workflow. Instead of manual kubectl commands, you manage rollbacks by reverting commits, ensuring your version control system remains the source of truth and all changes are auditable. Plural also provides a centralized dashboard to monitor deployment health and rollback progress across your entire fleet, giving you the visibility and control needed to manage incidents consistently and at scale.

Guides