World map

 

BM: Baca dalam Bahasa Melayu

World K2: Trays & Orders

ReplicaSets keep the count

You will learn: how a ReplicaSet keeps the right number of pods, and how it counts them.

Checked with Kubernetes 1.37 on 31 Oct 2026

The problem

Lunch time. You want 3 trays out, always. One tray slips and falls. Who notices, and who makes a new one?

Pick one answer.

Watch

The board says want 3, see 3. Deleting a pod makes it see 2, so it makes 1 more.

Want 3. See 3. All good.

Want3written on the order for trays
See33 ready
Do All goodGaps fixed: 0
Stalls: 3. Trays: 3 (3 ready). Waiting for a stall: 0.
dev-workerOpen
  • trays-7tmqp
  • trays-nzvvz
dev-worker2Open
  • trays-cg4fl

A ReplicaSet: The tray counter: keeps the right number of pods with matching labels. counts trays, again and again. Want 3, see 2? It makes 1 more. Tap delete on a tray and watch the board.

Try it

A ReplicaSet has 3 parts: how many (replicas), which trays count (selector), how to make one (template). Here the labels do not match. Fix it.

Fix the manifest, then press Apply.

trays.yaml18 lines

Try it

The rush is coming. Ask the ReplicaSet for 5 trays.

You are here: cluster kind-dev namespace default
Stalls: 3. Trays: 3 (3 ready). Waiting for a stall: 0.
dev-control-planeOpenManager

No trays here.

dev-workerOpen
dev-worker2Open
Time: +0s (sped up)

Predict

The ReplicaSet wants 3. You start one more pod by hand, with the label app=tray. What happens?

Pick one answer.

Check

You are here: cluster kind-dev namespace default
kubectl run creates the pod extra. A moment later get pods lists only the 3 trays: extra was one too many. Terminal output: $ kubectl run extra --image=nginx:1.29-alpine --labels=app=tray pod/extra created $ kubectl get pods NAME READY STATUS RESTARTS AGE trays-7tmqp 1/1 Running 0 16s trays-cg4fl 1/1 Running 0 16s trays-nzvvz 1/1 Running 0 16s

extra was created, then deleted at once. It matched app=tray, so it made 4. Labels decide what counts.

You did it!

You can now explain how a ReplicaSet keeps the count.

Go deeper (optional)

You will rarely write a ReplicaSet yourself. A Deployment makes them for you, and adds safe updates. That is the next lesson.

Real rep (optional): on a throwaway cluster, apply a ReplicaSet, delete one pod, then run kubectl describe rs trays. Its Events show each new pod.