Skip to main content
This lesson walks through the ReplicaSet lab solution step-by-step, preserving the lab question order and showing the exact commands and sample outputs used to inspect and fix the resources. Use this as a reference to understand ReplicaSet behavior, debugging steps, and common fixes. Quick reference - common commands:

1) How many pods exist on the system?

Run:
Initial output:
Conclusion: there are 0 pods initially.

2) How many ReplicaSets exist on the system?

Run:
Initial output:
Conclusion: there are 0 ReplicaSets initially. Later, after a ReplicaSet is created, it can be observed:
Example output:

3) What is the desired number of pods in the new ReplicaSet?

From the kubectl get replicaset output:
  • Desired = 4
Answer: 4

4) What image is used to create the pods in the new ReplicaSet?

To inspect the ReplicaSet template:
Relevant excerpt:
From the pod template, the image is busybox777. Answer: busybox777

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

From the kubectl get replicaset / kubectl describe output:
  • Ready = 0
So none of the pods are Ready.

6) Why are the pods not Ready?

Inspect a failing pod to find the root cause:
Relevant excerpt:
Reason: the kubelet cannot pull image busybox777 — the repository does not exist (invalid image name), causing ImagePullBackOff. Therefore pods are not Ready.

7) Delete a pod from the ReplicaSet and observe behavior

Delete one pod:
Then list pods:
Example output after deletion:
Explanation: Deleting a pod managed by a ReplicaSet causes the ReplicaSet controller to immediately create a replacement to maintain the desired count. That’s why you still see four pods even after deleting one.

8) Create a ReplicaSet from a definition file and fix apiVersion issue

List files in /root:
Attempt to create the first definition:
Error:
Inspect the file:
Problem: apiVersion is set to v1 but ReplicaSet is in the apps API group (apps/v1). Discover the correct API with:
Fix the file by updating apiVersion to apps/v1, then create it:
Success:
ReplicaSet belongs to the apps API group. Always use apiVersion: apps/v1. Use kubectl explain <kind> to discover the correct API version and available fields.

9) Fix the second definition file: selector vs template labels

Attempt to create the second file:
Error:
Inspect replicaset-definition-2.yaml (excerpt):
Problem: spec.selector.matchLabels is tier: frontend while the Pod template labels are tier: nginx. A ReplicaSet’s selector must match the Pod template labels so it can manage the created pods. Fix: make selector.matchLabels and template.metadata.labels match (for example, set both to tier: frontend), then create:
Success:
Check ReplicaSets:
Example output:

10) Delete replicaset-1 and replicaset-2

Delete both ReplicaSets:
Output:

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

The new-replica-set still references the invalid image busybox777. Edit the ReplicaSet to correct the container image:
In the editor, change the container image from busybox777 to busybox. Example edited snippet:
Save the change. The ReplicaSet object is updated, but existing pods do not automatically get replaced just because the ReplicaSet pod template changed.
Editing a ReplicaSet’s pod template updates the ReplicaSet object, but it does not replace existing pods. To apply the new template to running pods, either delete the existing pods (so the ReplicaSet recreates them) or recreate the ReplicaSet.

12) Recreate pods to pick up the new image

Delete the ReplicaSet’s pods so the controller will create new pods using the corrected image:
Watch pods being recreated:
Sample outputs as pods are created and become Running:
Verify ReplicaSet ready pods:
Example output:
Now the pods are running with the corrected busybox image. Note: When you change a ReplicaSet’s pod template, existing pods are not automatically replaced. Deleting the pods causes the ReplicaSet to recreate them with the new template.

13) Scale the ReplicaSet to 5 pods

Scale with kubectl scale:
Confirm:
Example output:
You can also edit the ReplicaSet and modify spec.replicas to scale.

14) Scale the ReplicaSet down to 2 pods (edit approach)

Edit the ReplicaSet:
Change spec.replicas to 2:
Save the change. The ReplicaSet controller will terminate excess pods to match the desired replica count of 2.
That’s it for this lab lesson. Links and References

Watch Video