Learning objectives
By the end of this module, you should be able to:
- Explain the Deployment → ReplicaSet → Pod ownership chain.
- Scale replicas declaratively.
- Observe rollout status and history.
Deployments manage desired replicas
A Deployment manages ReplicaSets, and ReplicaSets maintain the desired number of matching Pods. Operators normally manage the Deployment rather than creating ReplicaSets directly.
Rollouts replace Pods gradually
Changing the Pod template creates a new ReplicaSet. RollingUpdate strategy can bring new replicas up and old replicas down within availability/surge constraints.
Scaling changes desired count
Scaling changes how many Pod replicas the controller maintains. It does not duplicate local mutable state safely; applications should be designed for horizontal replication.
Worked examples
See the idea in practice.
Create and scale a Deployment
kubectl -n gnu-k8s-fundamentals create deployment web --image=nginx:alpine
kubectl -n gnu-k8s-fundamentals scale deployment web --replicas=3
kubectl -n gnu-k8s-fundamentals rollout status deployment/web
- The Deployment creates a ReplicaSet.
- The ReplicaSet maintains three Pods.
- rollout status waits for the desired rollout condition.
Hands-on lab
Lab — Scale and roll out safely
Goal: Create a Deployment, scale it, change its Pod template and inspect rollout ownership.
Before you start
- kubectl is installed and can reach the lab cluster.
- Use the dedicated gnu-k8s-fundamentals namespace unless a step explicitly says otherwise.
STEP 1Create the Deployment
kubectl -n gnu-k8s-fundamentals create deployment rollout-web --image=nginx:alpine
STEP 2Scale to three replicas
kubectl -n gnu-k8s-fundamentals scale deployment rollout-web --replicas=3
kubectl -n gnu-k8s-fundamentals rollout status deployment/rollout-web --timeout=120s
STEP 3Trigger a template rollout
kubectl -n gnu-k8s-fundamentals set env deployment/rollout-web COURSE_VERSION=v2
kubectl -n gnu-k8s-fundamentals rollout status deployment/rollout-web --timeout=120s
STEP 4Inspect ownership/history
kubectl -n gnu-k8s-fundamentals get deploy,rs,pods -l app=rollout-web
kubectl -n gnu-k8s-fundamentals rollout history deployment/rollout-web
STEP 5Clean up
kubectl -n gnu-k8s-fundamentals delete deployment rollout-web
Verify
- Three replicas become Available.
- Changing the Pod template creates a new ReplicaSet.
- The Deployment owns the rollout history.
Expected outcome
- The newest ReplicaSet ends with the desired replica count; the previous one is scaled down.
If it fails
- If rollout status times out, inspect Pods and Events before forcing changes.
- If Pods are not selected as expected, compare Deployment selector with template labels.
Real-world connectionDeployments are the default controller for replicated stateless services and are central to rolling application releases.
Avoid these traps
Common mistakes
- Managing ReplicaSets manually when a Deployment owns them.
- Expecting scaling to make a stateful application safe automatically.
- Changing labels so the Deployment selector no longer matches its Pod template.
Knowledge check
Can you explain it without looking back?
Open each answer only after you have tried to answer the question yourself.
1What normally creates ReplicaSets for an application?
A Deployment.
2What change triggers a new Deployment rollout?
A change to the Deployment Pod template.
3Does scaling change the container image?
No. It changes the desired replica count.