Overview

15 Automating application updates with Deployments

Deployments are the primary Kubernetes abstraction for running and updating stateless applications declaratively. A Deployment manages Pods indirectly through an automatically created ReplicaSet, letting you define a Pod template, label selector, desired replicas, and an update strategy. Because Deployments compute and add a pod-template-hash label, they adopt and manage only Pods created from their own template. You create and inspect Deployments with kubectl, scale them directly (the controller adjusts the underlying ReplicaSet), and can delete them while orphaning resources if needed. A common pitfall is unintentionally changing replica counts when reapplying manifests; omitting replicas in the original manifest or fixing the last-applied annotation prevents accidental rescaling.

Updating is where Deployments shine. Two strategies are supported: Recreate (delete all old Pods, then create new ones) and RollingUpdate (gradually replace old Pods while keeping the service available). Rolling behavior is governed by maxSurge and maxUnavailable, which control how many extra Pods can be added and how many can be unavailable at each step, and minReadySeconds, which delays rollout progress until new Pods have been stably ready for a period. You can change images via kubectl set image or patch multiple fields at once, pause/resume rollouts, watch progress, and roll back either to the previous or a specific recorded revision (history is retained via old ReplicaSets, bounded by revisionHistoryLimit). Readiness and availability differ: a Pod becomes “available” only after remaining ready for minReadySeconds, which, combined with probes and a progress deadline, helps prevent faulty versions from fully rolling out.

Beyond Recreate and RollingUpdate, several strategies can be composed with Kubernetes primitives. Canary can be approximated by pausing early in a rollout or by running a small canary Deployment alongside the stable one so only a fraction of traffic reaches the new version. A/B testing uses two Deployments and Services with Ingress routing based on attributes (for sticky, targeted experiments). Blue/Green runs two parallel Deployments and switches traffic by changing the Service’s selector, enabling instant cutover and easy rollback. Traffic shadowing mirrors production requests to a separate Deployment, discarding its responses to validate behavior under real load. While these patterns can be implemented manually with Deployments, Services, and Ingress, higher-level controllers can automate them in production environments.

The relationship between Deployments, ReplicaSets and pods
Label selectors in the Deployment and ReplicaSet, and the labels in the pods
Scaling a Deployment
The difference between the Recreate and the RollingUpdate strategies
Updating a Deployment
What happens with the ReplicaSets, pods, and the Service during a rolling update
Replacing pods when maxSurge is 0 and maxUnavailable is 1
Replacing pods when maxSurge is 1 and maxUnavailable is 0
How pods are replaced when both maxSurge and maxUnavailable are 1
A Deployment’s revision history
Implementing the Canary deployment strategy using two Deployments
Implementing the A/B strategy using two Deployments, Services, and an Ingress
Implementing a Blue/Green deployment with labels and selectors
Implementing traffic shadowing

Summary

  • Deployment is an abstraction over ReplicaSets. In addition to all the functionality that a ReplicaSet provides, Deployments also allow you to update pods declaratively. When you modify the Pod template, the old pods are replaced with new pods created using the updated template.
  • During an update, the Deployment controller replaces pods based on the strategy configured in the Deployment. In the Recreate strategy, all pods are replaced at once, while in the RollingUpdate strategy, they’re replaced gradually.
  • Pods created by a ReplicaSet are owned by that ReplicaSet. The ReplicaSet is usually owned by a Deployment. If the owner is deleted, the dependents are deleted by the garbage collector, but you can tell kubectl to orphan them instead.
  • Other deployment strategies aren’t directly supported by Kubernetes but can be implemented by appropriately configuring Deployments, Services, and the Ingress.

FAQ

What does a Deployment add on top of a ReplicaSet?A Deployment manages one or more ReplicaSets for you and automates updates of Pod templates. You change the desired state (image, labels, etc.) in the Deployment, and Kubernetes handles creating a new ReplicaSet, shifting traffic, and replacing Pods according to the chosen update strategy.
Why didn’t my new Deployment adopt existing Pods or my old ReplicaSet?Deployment-owned ReplicaSets use an extra pod-template-hash label derived from the Pod template. Existing Pods/ReplicaSets without that matching hash aren’t adopted, so the Deployment creates new Pods. To “adopt,” the template must be identical so the computed hash (and RS name suffix) matches.
How do I scale a Deployment safely without accidental changes later?Scale with kubectl scale or by editing the Deployment’s replicas. To avoid accidentally overwriting the replica count when reapplying manifests, omit the replicas field in the original manifest (it defaults to 1) and manage scale separately, or remove replicas from the last-applied annotation with kubectl apply edit-last-applied.
What’s the difference between the Recreate and RollingUpdate strategies?Recreate deletes all old Pods first, then starts all new Pods—simple but causes downtime. RollingUpdate replaces Pods gradually, keeping the Service available by scaling down the old ReplicaSet while scaling up the new one.
How do maxSurge and maxUnavailable affect a rolling update?maxSurge limits how many extra Pods (above the desired replicas) can be added during the update; maxUnavailable limits how many can be unavailable relative to desired replicas. They can be integers or percentages. Defaults are 25% for both.
What’s minReadySeconds and how is “Available” different from “Ready”?Ready indicates a Pod passes its readiness checks now. Available means the Pod has been Ready for at least minReadySeconds. The Deployment waits for availability when progressing a rollout, which can protect you from flapping or faulty new versions.
How can I pause or stage a rollout?Use kubectl rollout pause deployment NAME to pause and kubectl rollout resume deployment NAME to continue. Pausing lets you inspect initial Pods, make multiple changes to the template, or coordinate larger rollouts before resuming.
What should I check if no Pods appear after creating a Deployment?Describe the Deployment and its ReplicaSet. Look at status.conditions (e.g., ReplicaFailure) and events on the ReplicaSet for detailed errors (missing service account, RBAC, quotas, etc.). The root cause is usually visible in RS events.
How do I roll back a bad update or revert to a specific revision?Use kubectl rollout undo deployment NAME to revert to the previous revision, or add --to-revision=N for a specific one. View history with kubectl rollout history. Rollback only reverts the Pod template; other spec fields (strategy, replicas) remain as-is.
Can I do Canary, A/B, Blue/Green, or traffic shadowing with Kubernetes?Yes. Canary: run a small separate Deployment and send a small share of traffic (or pause the main rollout). A/B: two Deployments/Services with Ingress routing by header/cookie/etc. Blue/Green: two Deployments; switch the Service selector. Shadowing: mirror traffic at the proxy/Ingress to a non-serving Deployment. Tools like Argo Rollouts or Flagger can automate these.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Kubernetes in Action, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Kubernetes in Action, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Kubernetes in Action, Second Edition ebook for free