Kubernetes Deployments & Rollouts
Master Kubernetes Deployments — declarative desired state management, zero-downtime rolling updates, revisions, and rollbacks for stateless applications.
Kubernetes Deployments & Rollouts
A Deployment is a high-level Kubernetes controller that declaratively manages Pods and ReplicaSets. It provides automated self-healing, scaling, and zero-downtime rolling updates for stateless applications.
1. Complete Deployment Manifest
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-deployment
labels:
app: api-server
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # Can create 1 extra pod during rollout (total: 4)
maxUnavailable: 0 # 0 pods can be down during update (100% uptime)
selector:
matchLabels:
app: api-server
template:
metadata:
labels:
app: api-server
spec:
containers:
- name: api-server
image: ghcr.io/org/api:v1.2.0
ports:
- containerPort: 8080
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "512Mi"Apply the deployment:
kubectl apply -f deployment.yaml2. How Rolling Updates Work
Step 1 (Active v1): [Pod v1] [Pod v1] [Pod v1]
Step 2 (Surge v2): [Pod v1] [Pod v1] [Pod v1] + [Pod v2 (Starting)]
Step 3 (Ready v2): [Pod v1] [Pod v1] [Terminated] + [Pod v2 (Live)]
Step 4 (Progress): [Pod v1] [Terminated] + [Pod v2 (Live)] [Pod v2 (Live)]
Step 5 (Finished): [Pod v2] [Pod v2] [Pod v2]3. Managing Rollouts with kubectl
Update Container Image
kubectl set image deployment/api-deployment api-server=ghcr.io/org/api:v1.3.0Check Rollout Status in Real-Time
kubectl rollout status deployment/api-deploymentView Rollout Revision History
kubectl rollout history deployment/api-deploymentInstantly Roll Back to Previous Revision
kubectl rollout undo deployment/api-deploymentOr roll back to a specific revision:
kubectl rollout undo deployment/api-deployment --to-revision=24. Scaling Pods
Declarative Scaling
Update replicas: 5 in deployment.yaml and run kubectl apply -f deployment.yaml.
Imperative Scaling
kubectl scale deployment api-deployment --replicas=5Kubernetes Pods & Workload Basics
Understand Pods — the smallest deployable execution units in Kubernetes, shared networking, multi-container sidecars, init containers, and pod lifecycles.
Kubernetes ReplicaSets
Understand ReplicaSets — the low-level controller maintaining a stable set of replica Pods, label selectors, and self-healing mechanics.