Skip to main content
This guide walks through the ReplicaSet lab solution step by step. Each numbered task mirrors the lab questions and includes the commands, outputs, diagnosis, and fixes. Use this as a reference for troubleshooting ReplicaSets, image pull errors, label/selector mismatches, and scaling.

1) How many pods exist on the system?

Run:
Output:
Answer: 0 pods.

2) How many ReplicaSets exist on the system?

Run:
Output:
Answer: 0 ReplicaSets. Later, a ReplicaSet is created. Re-check:
Output:
Describe the ReplicaSet to inspect the pod template and image:
Key excerpt from the describe output:
Question: What image is used to create the pods in the new ReplicaSet? Answer: busybox777.

3) How many pods are Ready in the new ReplicaSet?

From the describe/get output above:
  • READY is 0
  • Pod Status shows 0 Running / 4 Waiting
Answer: 0 pods are Ready. Why are the pods not Ready? Inspect one of the pods:
Relevant excerpt showing the error:
Cause: The image busybox777 does not exist (or is private), so kubelet cannot pull it and containers fail to start with ImagePullBackOff.

4) Delete any one of the pods in the ReplicaSet and observe what happens

Delete a pod managed by the ReplicaSet:
Then check pods:
Example output after delete:
Explanation: ReplicaSet enforces the desired replica count. When you delete a pod that the ReplicaSet manages, the controller creates a replacement pod to maintain the desired number of replicas.
ReplicaSet ensures that a specified number of pod replicas are running at any given time. Deleting a pod managed by a ReplicaSet causes the ReplicaSet controller to automatically create a replacement pod.

5) Create a ReplicaSet using the definition file at /root (fix issues if any)

List files:
Try to create the first ReplicaSet:
Error:
Inspect the YAML:
Problem: apiVersion: v1 is incorrect for ReplicaSet. ReplicaSet belongs to apps/v1. Find correct API version:
Fix the YAML to:
Create the corrected ReplicaSet:
Output:
SEO tip: ReplicaSets are part of the apps API group — use apiVersion: apps/v1 for compatibility with modern Kubernetes versions.

6) Fix the issue in the second file and create the ReplicaSet

Attempt to create:
Error:
Inspect the YAML:
Problem: The ReplicaSet selector (tier: frontend) does not match the pod template labels (tier: nginx). ReplicaSet requires the selector to match the template labels exactly so it can manage the pods it creates. Fix: Make the labels match the selector. For example, change the template label to frontend:
After fixing the mismatch, create the ReplicaSet:
Output:
Verify ReplicaSets:
Example output:
Tip: Always ensure spec.selector.matchLabels matches spec.template.metadata.labels. Kubernetes will reject ReplicaSets where the selector does not cover the template labels.

7) Delete the two newly created ReplicaSets

Delete both ReplicaSets:
Or delete both in one command:
Output example:

8) Fix the original ReplicaSet to use the correct busybox image

We still have new-replica-set whose pods are failing because of the wrong image name (busybox777). Edit the ReplicaSet to correct the image:
In the editor, locate the container image and change:
Save and exit. This updates the ReplicaSet’s pod template to refer to the correct image. Important: Updating the ReplicaSet template does not retroactively replace existing pods. The ReplicaSet will continue reporting the current pods until they are recreated based on the new template. Two ways to apply the updated template to running pods:
  • Delete the pods managed by the ReplicaSet; the ReplicaSet controller will create replacements using the updated template.
  • Delete and re-create the ReplicaSet (not recommended for live workloads).
Delete the old pods:
Watch pods come up:
Expected new pod list eventually becomes:
Check ReplicaSet status:
Output:

9) Scale the ReplicaSet up to 5 pods

Scale using kubectl:
Output:
Verify pods:
You should see an additional pod:
Alternative: Edit the ReplicaSet and update spec.replicas manually:

10) Scale the ReplicaSet down to 2 pods (edit method)

Edit the ReplicaSet:
Change:
Save and exit. The ReplicaSet controller will terminate excess pods until only two replicas remain. Confirm:
You should see the ReplicaSet reflected with DESIRED 2 and the pod list reduced accordingly.
References and further reading: That’s it for this lab.

Watch Video