A Deployment is the workload object you should reach for first when running a stateless service on Kubernetes. It owns a ReplicaSet, which owns Pods. The Deployment’s job is to safely roll forward when you change the Pod template and to keep the right number of replicas running while it does. This article covers what each layer does, the rollout strategy fields you should set deliberately, and the rollout/rollback workflow you’ll use most days.
How to verify
For any Deployment, three commands tell you the state:
kubectl get deploy,rs,pod -l app=web -o wide
kubectl rollout status deployment/web
kubectl describe deployment/web | sed -n '/StrategyType\|RollingUpdate\|Conditions/,/^$/p'
The first shows the chain (Deployment → ReplicaSets → Pods); a healthy rollout has exactly one ReplicaSet with non-zero desired replicas, the others scaled to zero but kept for rollback. rollout status blocks until the rollout finishes or a deadline trips. describe surfaces the strategy and the Available/Progressing conditions — the latter is what makes a stuck rollout obvious.
To see history:
kubectl rollout history deployment/web
kubectl rollout history deployment/web --revision=4
What’s happening
A Deployment is declarative. You write the desired state (image, env, replicas, strategy) and the controller does the work. The mechanism: when the Pod template changes, the Deployment creates a new ReplicaSet with the new template and gradually shifts replicas from the old ReplicaSet to the new one, bounded by maxSurge and maxUnavailable. Old ReplicaSets are kept around (up to revisionHistoryLimit, default 10) so you can roll back instantly without re-pulling images or recomputing manifests.
ReplicaSet is the layer below — it owns Pods by label selector and keeps the count at the desired number. You rarely create a ReplicaSet directly; the Deployment owns its lifecycle. The selector is immutable once set, which is the most common gotcha when you try to “fix” labels on an existing Deployment.
The two strategies are RollingUpdate (default) and Recreate. Recreate scales the old ReplicaSet to zero before bringing up the new one — useful when two versions cannot coexist (a database schema migration in the same pod, an exclusive resource lock), painful otherwise because it causes a hard outage during deploys.
The procedure
-
Create a Deployment with explicit strategy. The defaults (
maxSurge: 25%,maxUnavailable: 25%) are fine for many cases, but state them so they’re reviewable in Git.apiVersion: apps/v1 kind: Deployment metadata: name: web spec: replicas: 6 selector: matchLabels: { app: web } strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 revisionHistoryLimit: 10 minReadySeconds: 15 progressDeadlineSeconds: 600 template: metadata: labels: { app: web } spec: containers: - name: web image: registry.example.com/web:1.4.2 readinessProbe: httpGet: { path: /healthz, port: 8080 } periodSeconds: 5 -
Roll forward by changing the image.
kubectl set imageis fine in a pinch, but the source of truth should be the YAML committed to Git.kubectl set image deployment/web web=registry.example.com/web:1.4.3 kubectl rollout status deployment/web --timeout=10m -
Pause and resume for batched changes. Useful when you want to change several fields and trigger one rollout, not three.
kubectl rollout pause deployment/web kubectl set image deployment/web web=registry.example.com/web:1.4.3 kubectl set env deployment/web LOG_LEVEL=info kubectl rollout resume deployment/web -
Roll back to a previous revision when the new one is misbehaving. The previous ReplicaSet still exists; rollback is cheap.
kubectl rollout undo deployment/web kubectl rollout undo deployment/web --to-revision=4 -
Scale independently of a rollout. Scaling does not touch the Pod template; it just changes
replicason the current ReplicaSet.kubectl scale deployment/web --replicas=10 -
Inspect the controlling ReplicaSet when you want to know which version of the template a Pod belongs to. Pods carry a
pod-template-hashlabel that ties them to a ReplicaSet.kubectl get pods -l app=web --show-labels kubectl get rs -l app=web
Common pitfalls
maxUnavailable: 25%with 4 replicas means 1 Pod down during a rollout — which is fine for most apps but disastrous for a quorum-bound service; setmaxUnavailable: 0for those and pay with longer rollouts.- A missing
readinessProbemakes rolling updates dangerous: Kubernetes considers a Pod “Ready” as soon as the container is Running, so the old version is killed before the new one is actually serving. progressDeadlineSeconds(default 600) marks the DeploymentProgressing=Falseif it hasn’t moved in that window — without this, a wedged rollout sits forever and your CI never fails.minReadySecondsis the cooling-off period after a Pod becomes Ready before the rollout proceeds; setting it to 15-30s smooths out flaky readiness on cold starts.- Changing the selector on an existing Deployment forces you to recreate it — the API server rejects the update; plan label changes during a downtime window.
We operate Deployments for clients with rollout strategies that match the actual SLO — staged surge for tight quorum, zero-downtime defaults for stateless web, and a rollback runbook that doesn’t require remembering --to-revision. See /en/services/managed-operations/.