Appearance

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.

  1. Deployment owns ReplicaSet

    The Deployment declares replicas and a Pod template. Its controller creates or reuses the ReplicaSet representing that template.

  2. ReplicaSet owns Pods

    The ReplicaSet controller observes its target and creates three Pod objects. It is the immediate controller responsible for this count.

  3. Scheduler and kubelet make them run

    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.

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: 80

Apply 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 wide

Scale 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_NAME

What 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
Deploymentreplicas-demoDesired 2
ReplicaSetweb replicasTarget 2
Pods managed by this ReplicaSet
  • Pod AReady
  • Pod BReady
  • Pod CEmpty slot
Two ready Pods

The Deployment asks for 2 replicas. Its ReplicaSet manages two Pods, and both are ready.

Text walkthrough
  1. Two ready Pods

    The Deployment asks for 2 replicas. Its ReplicaSet manages two Pods, and both are ready.

  2. Deployment requests 3

    The API records replicas: 3. The Deployment controller adjusts the ReplicaSet’s target.

  3. ReplicaSet needs one more Pod

    The ReplicaSet now has a target of 3 with only 2 Pods. Its controller creates one more.

  4. The third Pod is starting

    The ReplicaSet has 3 Pods. The new Pod still has to be scheduled, start its container, and become ready.

  5. 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.

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

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu