Deployment
A Deployment is the standard Kubernetes controller for running stateless applications. It keeps the desired number of identical pod replicas running, replaces failed pods automatically, and rolls out new versions without downtime.
How a Deployment works
You declare a pod template and a replica count. The Deployment creates a ReplicaSet, which creates and owns the pods. When you change the template, such as a new image tag, the Deployment creates a new ReplicaSet and shifts replicas from the old one to the new one. The old ReplicaSet is kept at zero replicas so you can roll back.
payment-api"] -->|"manages"| R2["ReplicaSet v3.2.0
3 replicas"] D -.->|"kept for rollback"| R1["ReplicaSet v3.1.0
0 replicas"] R2 --> P1["Pod 1"] R2 --> P2["Pod 2"] R2 --> P3["Pod 3"] classDef ctl fill:#326CE5,color:#ffffff classDef rs fill:#FFEDD5,color:#1E293B classDef pod fill:#D1FAE5,color:#1E293B class D ctl class R1,R2 rs class P1,P2,P3 pod
A production-ready spec
apiVersion: apps/v1kind: Deploymentmetadata: name: payment-api namespace: productionspec: replicas: 3 selector: matchLabels: app: payment-api strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 # never drop below desired capacity template: metadata: labels: app: payment-api spec: containers: - name: payment-api image: registry.example.com/payment-api:v3.1.0 # pinned tag resources: requests: { cpu: "250m", memory: "256Mi" } limits: { memory: "512Mi" } readinessProbe: httpGet: { path: /health, port: 8080 } periodSeconds: 5 livenessProbe: httpGet: { path: /health, port: 8080 } initialDelaySeconds: 30 terminationGracePeriodSeconds: 30Daily commands
kubectl set image deployment/payment-api payment-api=registry.example.com/payment-api:v3.2.0 -n productionkubectl rollout status deployment/payment-api -n productionkubectl rollout history deployment/payment-api -n productionkubectl rollout undo deployment/payment-api -n productionkubectl rollout restart deployment/payment-api -n productionkubectl annotate deployment payment-api kubernetes.io/change-cause="v3.2.0 UPI retry" -n productionDeployment vs StatefulSet vs DaemonSet
| Controller | Use for |
|---|---|
| Deployment | Stateless apps with interchangeable pods |
| StatefulSet | Stable identity and per-pod storage |
| DaemonSet | One pod per node |
Remember
kubectl rollout undois your fastest recovery path after a bad release, usually completing as quickly as a normal rollout.
SecurityNever deploy with the
latesttag. Rollbacks and audits become unreliable. Use a version or commit SHA.
Common MistakeOmitting a readiness probe. Pods then receive traffic the moment the container starts, before the app is ready.
Frequently Asked Questions
Why does a Deployment manage a ReplicaSet instead of pods directly?
The extra layer makes versioned rollouts possible. Each template change creates a new ReplicaSet, and the old one stays at zero replicas so rollback just scales it back up.
What commonly causes outages during Deployment updates?
Missing readiness probes, and surge or unavailability settings that are too aggressive for small replica counts. Use maxUnavailable: 0 for production services that cannot lose capacity.
Does kubectl apply or kubectl set image trigger a rollout?
Either triggers one if the pod template changes. Changing only the replica count does not create a new ReplicaSet.