Deployments and ReplicaSets
Run several copies of an application and trace which controller replaces a missing Pod.
What you will understand
- Trace ownership from a Deployment through a ReplicaSet to a Pod.
- Explain what a change to the replica count asks the controllers to do.
- Use Pod status to distinguish having enough copies from having enough ready copies.
Builds on: Configuration and Secrets
How Deployments, ReplicaSets, and Pods fit together
Suppose a small shop serves its product catalog from one web Pod. The shop wants three copies so a single Pod can disappear without removing every backend. It also needs somewhere to record which image the next copy should run. A Deployment manages interchangeable copies of an application. Its Pod template describes each copy, and its replica count states how many copies the shop wants.
A Deployment creates a ReplicaSet for a version of that template. The ReplicaSet creates and removes Pods to reach its assigned count. In a stable Deployment with three replicas, one ReplicaSet normally manages three Pods. During an update the Deployment can divide the desired copies between two ReplicaSets. Each ReplicaSet keeps track of the Pods it controls, while the Deployment coordinates the release.
A Deployment manages a hierarchy
The Deployment controls the ReplicaSet. The ReplicaSet controls the Pods. Placement and execution happen separately on the scheduling and node paths.
Deployment owns ReplicaSet
- Deployment controllerReplicaSet target: 3create / set target
- Deployment replicas: 3ReplicaSet target: 3owns
The Deployment declares replicas and a Pod template. Its controller creates or reuses the ReplicaSet representing that template.
ReplicaSet owns Pods
- ReplicaSet controllerReplicaSetreconciles target
- ReplicaSetPod Aowns
- ReplicaSetPod Bowns
- ReplicaSetPod Cowns
The ReplicaSet controller observes its target and creates three Pod objects. It is the immediate controller responsible for this count.
Scheduler and kubelet make them run
- SchedulerManaged Pod readybind node
- Worker kubelet + runtimeManaged Pod readystart assigned containers
The scheduler binds new Pods; node kubelets use runtimes to start them. Neither task is performed by the replica counter.
One active ReplicaSet is shown; later lessons add an old revision during rollout.
Explore another case
Write a Deployment for three copies
Save the YAML as replicas-demo.yaml. The top-level metadata.name names the Deployment. Under spec.template is a recipe for each Pod, including the nginx container image and its port. The template label app: replicas-demo matches spec.selector.matchLabels. The API rejects a Deployment when its selector and its template labels disagree. Choose a label that identifies this workload so that separate controllers do not match the same Pods.
apiVersion: apps/v1
kind: Deployment
metadata:
name: replicas-demo
spec:
replicas: 3
selector:
matchLabels:
app: replicas-demo
template:
metadata:
labels:
app: replicas-demo
spec:
containers:
- name: web
image: nginx:1.27.5
ports:
- name: http
containerPort: 80Apply the manifest in your lab namespace. The rollout command waits for the Deployment to report success, so give it time to download the image and start the copies. Look for three ready Pods. The ReplicaSet and Pod names include generated suffixes. Record two of the Pod names before experimenting.
kubectl apply -f replicas-demo.yaml
kubectl rollout status deployment/replicas-demo --timeout=120s
kubectl get deployment replicas-demo
kubectl get rs -l app=replicas-demo
kubectl get pods -l app=replicas-demo -o wideScale the Deployment and delete a Pod
Read one Pod’s owner reference. It identifies a ReplicaSet. On the ReplicaSet, look for Controlled By to find the Deployment. Scale the Deployment from two to three in the scene and see which object creates the extra Pod. In the lab, deleting a managed Pod leaves the assigned count unchanged, so the ReplicaSet makes a replacement. The replacement has its own name and UID.
# Replace the placeholder with one real Pod name from the listing above.
kubectl get pod ACTUAL_POD_NAME -o jsonpath='{.metadata.ownerReferences}'
# Inspect the owning ReplicaSet found in that output.
kubectl describe rs ACTUAL_REPLICASET_NAMEWhat creates the third Pod?
Start with two ready Pods. Ask the Deployment for one more and follow the change to the ReplicaSet and the new Pod.
- Desired
- 2
- Pods created
- 2
- Ready
- 2
- Pod AReady
- Pod BReady
- Pod CEmpty slot
The Deployment asks for 2 replicas. Its ReplicaSet manages two Pods, and both are ready.
Text walkthrough
- Two ready Pods
The Deployment asks for 2 replicas. Its ReplicaSet manages two Pods, and both are ready.
- Deployment requests 3
The API records replicas: 3. The Deployment controller adjusts the ReplicaSet’s target.
- ReplicaSet needs one more Pod
The ReplicaSet now has a target of 3 with only 2 Pods. Its controller creates one more.
- The third Pod is starting
The ReplicaSet has 3 Pods. The new Pod still has to be scheduled, start its container, and become ready.
- All three Pods are ready
The new Pod is ready. The two original Pods stayed in place throughout the scale-up.
One Deployment and one active ReplicaSet. The visual shows changes observed through the API. Scheduling and startup are condensed and the timing is illustrative.
Explore another case
Try both operations in the Deployments and recovery lab. Compare the resulting Pod names and ready replica counts. The older copies can keep running while the newest Pod starts.
Count ready replicas and check their placement
Three Pods in the list can include a Pod waiting for a node or one failing to pull its image. To understand what can handle requests, look at readiness and verify the Service endpoints as well. Three copies can also land on the same node unless you configure placement. They protect against some Pod failures but still share that node as a possible point of failure.
After changing the replica count interactively, update the manifest if you want that count to persist the next time somebody applies the file.
Check your understanding
One of three Pods is stuck in ImagePullBackOff. Will its ReplicaSet create a fourth Pod to replace it?
The stuck Pod still counts as an active Pod controlled by the ReplicaSet. The kubelet retries pulling the image for that Pod. The Deployment can have three replicas and only two ready copies, so investigate the image reference or pull credentials before expecting the ready count to rise.
Primary documentation
Go to the source
Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise