Kubernetes Deployments Explained: How Rollouts and Rollbacks Work

Kubernetes Deployments Explained: How Rollouts and Rollbacks Work

Kubernetes deployments explained in plain terms: a Deployment is the controller that runs your application, keeps the right number of pods alive, and updates them safely when you ship a new version. If you want to release software on Kubernetes without downtime, the Deployment is the object that does the work. The central question is how a Deployment actually manages an update, and the answer is that it creates a new ReplicaSet for the new version, then gradually scales the new pods up and the old ones down, so traffic keeps flowing throughout.

That gradual replacement is called a rolling update, and it is the default behaviour. You change the image, an environment variable or any other part of the pod template, and the Deployment handles the transition. If the new version fails, you can roll back to the previous one with a single command.

Deployments are the standard way to run stateless applications on Kubernetes. They sit above ReplicaSets, which sit above pods, and each layer has one job. Understanding that chain is the key to understanding how releases work on the platform. Our guide to what Kubernetes is and when to use it covers the wider picture if you are starting from scratch.

Key takeaways

  • A Deployment manages ReplicaSets, which manage pods: each layer has one job.
  • The default rolling update replaces pods gradually, so the application stays available.
  • maxSurge and maxUnavailable both default to 25% and control the speed and safety of a rollout.
  • Readiness probes decide when a new pod is safe to receive traffic.
  • Kubernetes keeps old ReplicaSets by default, so a bad release can be rolled back quickly.

What is a Kubernetes Deployment?

A Deployment is a controller that manages stateless applications. You describe the desired state: which container image to run, how many replicas you want, which ports to expose, and how updates should behave. The Deployment then works continuously to make reality match that description.

When you create a Deployment, it creates a ReplicaSet, and the ReplicaSet creates the pods. When you update the Deployment, it creates a new ReplicaSet for the new pod template and scales the old one down. This layering matters because each object has a narrow responsibility: the Deployment decides what version should run, the ReplicaSet keeps the right number of pods running, and the pods run the containers.

Deployments also self-heal. If a pod crashes or a node fails, the ReplicaSet notices the missing replica and starts a replacement. That is why you should never create bare pods in production: a bare pod that dies stays dead, while a pod owned by a Deployment is recreated automatically.

Best for: stateless applications such as web servers, APIs and background workers that can run as any number of identical replicas. Stateful workloads that need stable identities and storage belong in a StatefulSet instead.

How a rolling update works

A rolling update begins when you change anything in the pod template, most often the container image. The Deployment controller creates a new ReplicaSet with the new template, then scales it up a few pods at a time while scaling the old ReplicaSet down. At every point during the update, a mix of old and new pods serves traffic, so the application remains available throughout.

Two fields control the pace. maxSurge sets how many extra pods may exist above the desired replica count during the update, and maxUnavailable sets how many pods may be missing below it. Both default to 25 per cent of the replica count, and both accept an absolute number or a percentage. The rounding rules differ: maxSurge rounds up and maxUnavailable rounds down.

With four replicas and the defaults, Kubernetes may run up to five pods and must keep at least three available. For a safer rollout on a critical service, set maxUnavailable to 0 and maxSurge to 1: a new pod must be ready before an old one is removed, so full capacity is maintained. On a cluster with no spare capacity, the opposite setting, maxSurge 0 and maxUnavailable 1, removes one old pod before each new one starts.

Watch a rollout with the rollout status command, which reports progress until every new pod is ready. If a rollout stalls, the first things to check are the new pods themselves: a bad image, a failing readiness probe or a missing configuration value will all stop the update in its tracks. Our guide to common Kubernetes problems and practical troubleshooting explains how to read those symptoms.

Rolling updates compared with other strategies

Strategy How it works Downtime When to use it
Rolling update Replaces pods gradually, old and new run side by side None, if probes are correct Default choice for most stateless services
Recreate Stops all old pods before starting new ones Yes, for the whole update When old and new versions cannot run together
Blue-green Runs the new version fully, then switches traffic at once None When you need instant switching and instant rollback
Canary Sends a small share of traffic to the new version first None When a release needs real traffic before full rollout

Only the first two strategies are built into the Deployment object itself. Rolling update is the default, and Recreate is chosen by setting the strategy type. Blue-green and canary releases need extra tooling, such as a service mesh or a progressive delivery controller, because the Deployment alone cannot split traffic by percentage.

The Recreate strategy exists for applications that cannot tolerate two versions running at once, for example when a new version changes a shared data format. It causes downtime by design, so use it only when the application genuinely requires it, and schedule the update for a quiet period.

A whiteboard in a bright office with a hand-drawn flow diagram of empty boxes joined by arrows
Plan a rollout before you start it: sketch the order in which pods are replaced, decide the surge and unavailable settings, and agree what a failed rollout looks like.

Rollbacks: undoing a bad release

Kubernetes keeps old ReplicaSets so you can return to a previous version. By default it keeps ten old revisions, controlled by the revision history limit. A rollback simply scales the previous ReplicaSet back up and the current one down, which is fast because the old pods are recreated from a template the cluster already knows.

Roll back with the rollout undo command, which reverts to the previous revision. You can also roll back to a specific revision if you know its number, which is useful when the last two releases were both bad. Check the rollout history first to see which revision is which and what changed in each one.

A rollback restores the previous pod template, but it does not undo anything outside Kubernetes. Database migrations, external configuration changes and data written by the bad version are not reversed, so a rollback is not a complete undo. For releases that change a database schema, plan the migration so the old version can still run against the new schema, or the rollback will fail at the application level even though the pods come back.

The progress deadline is the safety net for a rollout that never completes. By default, Kubernetes waits 600 seconds for a Deployment to make progress before marking it failed. A failed rollout leaves the old pods serving traffic, which is usually the outcome you want while you investigate.

Probes, readiness and zero-downtime releases

A rolling update is only safe if Kubernetes knows when a new pod is ready to serve traffic. That is the job of the readiness probe. Until the readiness probe passes, the pod is running but receives no traffic, and the Deployment waits before removing an old pod. Without a readiness probe, Kubernetes assumes a pod is ready as soon as its container starts, which can send traffic to an application that is still warming up.

The liveness probe plays a different role: it asks whether the container is still alive, and restarts it if the probe fails. The two probes should check different things. A readiness probe should test whether the application can serve requests, for example by calling a health endpoint that checks database connectivity. A liveness probe should test only whether the process is stuck, because an aggressive liveness probe restarts containers that are merely slow.

Two more settings help releases go smoothly. minReadySeconds makes the Deployment wait a few seconds after a pod becomes ready before counting it as available, which catches pods that pass a probe once and then fail. The preStop hook lets a container finish in-flight requests and deregister itself before it is killed, which prevents errors at the end of a pod’s life. Our practical Kubernetes tutorial shows these settings in a working example.

Scaling a Deployment

Scaling a Deployment is a one-line change to the replica count, and the ReplicaSet adds or removes pods to match. Scaling up is immediate and safe for stateless applications, because every pod is identical. Scaling down removes pods one at a time, and the preStop hook gives each one a chance to finish its work.

For automatic scaling, the HorizontalPodAutoscaler adjusts the replica count based on CPU, memory or custom metrics. It works best when the application is genuinely stateless and when resource requests are set correctly, because the autoscaler scales on utilisation relative to the request. A Deployment with no requests gives the autoscaler nothing to measure against.

Vertical scaling, changing the CPU and memory a pod requests, is a different tool. The VerticalPodAutoscaler can adjust requests automatically, but changing requests restarts the pod, so it suits workloads with predictable patterns rather than spiky traffic. Most teams start with manual scaling, add horizontal autoscaling when traffic varies, and treat vertical scaling as a tuning exercise.

Kubernetes Deployment checklist

  • Run stateless applications as Deployments, never as bare pods.
  • Set a readiness probe that reflects whether the application can really serve traffic.
  • Set a liveness probe that only detects a genuinely stuck process.
  • Choose maxSurge and maxUnavailable deliberately; use maxUnavailable 0 for critical services.
  • Set resource requests and limits so scheduling and autoscaling work properly.
  • Add a minReadySeconds value of a few seconds to catch pods that fail shortly after starting.
  • Use a preStop hook so pods drain cleanly instead of dropping requests.
  • Keep the revision history limit at its default so rollbacks remain possible.
  • Test the rollback path before you need it, including any database migration.
  • Watch the rollout status after every release and confirm all pods reach Ready.

Frequently asked questions

What is a Kubernetes Deployment?

A Deployment is a controller that manages stateless applications. It owns ReplicaSets, which own pods, and it handles rolling updates, scaling and rollbacks so you do not have to manage pods directly.

What is the difference between a Deployment and a ReplicaSet?

A ReplicaSet keeps a set number of identical pods running. A Deployment manages ReplicaSets: it creates a new one on every update and rolls traffic between them. You create Deployments; ReplicaSets are created for you.

How do I roll back a Kubernetes Deployment?

Use the rollout undo command to return to the previous revision, or specify a revision number to go further back. Kubernetes keeps ten old ReplicaSets by default, so recent versions remain available for rollback.

What happens if a rolling update fails?

The Deployment stops making progress and, after the progress deadline of 600 seconds by default, is marked as failed. The old pods keep serving traffic, so the application stays up while you investigate the new pods.

When should I use Recreate instead of a rolling update?

Only when the old and new versions cannot run at the same time, for example when a release changes a shared data format. Recreate causes downtime by design, so schedule it carefully and only when the application genuinely requires it.

Latest articles

Scroll to Top