Module 3 ยท Lesson 3.1
Deployments and ReplicaSets
You've been creating bare Pods so far. In practice, you almost never do that โ you create a Deployment, and it creates everything else for you.
The chain: Deployment โ ReplicaSet โ Pods
A Deployment declares what you want: this image, this many replicas, this update strategy. It doesn't manage pods directly โ it creates and manages a ReplicaSet, and the ReplicaSet is what actually watches over a set of identical Pods, using a label selector (last lesson!) to know which ones are "its."
Deployment โ ReplicaSet โ Pods
Deployment: web
spec.replicas = 3
ReplicaSet: web-7d9f6c
desired: 3 ยท current: 3
Why the extra layer? Because a rolling update needs two ReplicaSets to exist briefly โ the old one scaling down while the new one scales up โ and the Deployment is what orchestrates that handoff. You'll see this directly in the next lesson.
Scaling vs. updating: two different operations
This distinction matters more than it looks like it should:
- Scaling (
replicas: 2โreplicas: 4) changes how many โ the pod template is untouched, so the existing ReplicaSet just grows. No new revision, no rolling update, just more of the exact same pods. - Updating (changing the image, env vars, or anything in
spec.template) changes what โ this creates a brand-new ReplicaSet (new revision) and triggers a rolling update between old and new.
You'll do exactly the first one in this lesson's lab, and exactly the second one in the next.
Who owns what
Every object a controller creates on your behalf carries an
ownerReference back to its creator: Pods point to their ReplicaSet, the
ReplicaSet points to its Deployment. This is also how garbage collection
works โ delete the Deployment, and Kubernetes cascades the delete down
through the ReplicaSet to every Pod, because of this chain, not because
anything is hardcoded to know about Deployments specifically.
The infrastructure analogy
A Deployment is closest to an auto-scaling group's launch template plus its desired-capacity setting, combined โ except, again, it's continuously enforced rather than evaluated on a schedule, and "launching a new version" (the rolling update) is a first-class, built-in operation instead of a separate deploy script you maintain yourself.
๐งช Lab: lab-05-deployments
Preview onlyGoal
See the Deployment โ ReplicaSet โ Pods chain for real, and the difference between scaling (same ReplicaSet) and changing the pod template (new ReplicaSet โ that's next lesson's lab).
Tasks
- Apply the starting manifests:
kubectl apply -f manifests/ - List the ReplicaSet Kubernetes created for you, and the pods it owns:
kubectl get rs -n lab-05-deploymentsandkubectl get pods -n lab-05-deployments -o wide - Check who owns those pods:
kubectl get pod <pod-name> -n lab-05-deployments -o jsonpath='{.metadata.ownerReferences}'โ it should point at the ReplicaSet, not the Deployment directly (the Deployment owns the ReplicaSet, which owns the Pods). - Edit
manifests/deployment.yaml: changereplicas: 2toreplicas: 4. - Re-apply:
kubectl apply -f manifests/deployment.yaml - Run
kubectl get rs -n lab-05-deploymentsagain โ still exactly one ReplicaSet, just scaled to 4. You changed the replica count, not the pod template, so no new revision was needed.
Check
Run the check once the Deployment reports 4/4 ready.
This lab runs against a real local Kubernetes cluster with an automated grader โ clone the repo and run make start to do it for real.
๐ Quiz
1. What does a Deployment actually manage directly?
2. You run `kubectl scale deployment web --replicas=6`. Does this create a new ReplicaSet?scenario
3. If you delete a Deployment, what happens to its ReplicaSet and Pods?
4. You change a Deployment's env var in spec.template.spec.containers[0].env. What happens?scenario
5. In the auto-scaling-group analogy, a Deployment is closest to:
Progress isn't saved in this preview โ run the course locally to track completion and grade labs for real.