BM: Baca dalam Bahasa Melayu
World K5: Lunch Rush
Pick a stall: nodeSelector and affinity
You will learn: how to send a tray only to stalls with the right label.
Checked with Kubernetes 1.37 on 31 Oct 2026
The problem
kind-dev namespace defaultThe fast tray says Pending. It never starts. What is it waiting for?
Watch
fast.yaml carries a sign. A nodeSelector: A sign on the tray: "only stalls with this label". says: “only stalls with this label.”
spec:
nodeSelector:
disk: ssdWhich stall may take the fast tray?
Pick one answer.
Try it
Put every tray on a stall. Read the signs first.
Tap a tray, then tap a stall. Or drag the tray.
Waiting trays
- stall-a
- stall-b
- Pending
Trays that fit on no stall wait here.
Hint
fast needs disk=ssd. slow-ok needs disk=hdd. tray-1 has no sign: any stall works.Check
kind-dev namespace defaultThose are the scheduler’s real words. In plain words: one stall is locked. Two have the wrong label. No stall says disk=ssd.
Try it
Give stall dev-worker2 the sign. The waiting tray should move in.
kubectl label nodes dev-worker2 disk=ssdkind-dev namespace defaultdev-control-planeOpenManagerNo trays here.
dev-workerOpenNo trays here.
dev-worker2OpenNo trays here.
- fastPending
Hint
Copy the command above. Then watch the waiting tray.Watch
node affinity: A wish list for stalls: must-have rules and nice-to-have rules. is a wish list: must-haves (required) and nice-to-haves (preferred). The fast tray needs ssd. It would like the front zone. Sort them.
Drag a card into a box. Or tap the card, then tap the box.
In YAML, the two lists look like this:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- { key: disk, operator: In, values: [ssd] }
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 50
preference:
matchExpressions:
- { key: zone, operator: In, values: [front] }Predict
The fast tray runs on dev-worker2. Now you remove the label: kubectl label nodes dev-worker2 disk-. What happens to the tray?
Pick one answer.
You did it!
You can now send a tray to the right stall with labels.
Go deeper (optional)
kubectl get nodes --show-labels lists every stall’s labels. Built-in ones include kubernetes.io/hostname and, in clouds, topology.kubernetes.io/zone. Pod affinity puts trays near other trays. Anti-affinity keeps them apart.
Real rep (optional): use a throwaway kind cluster. Label a worker, then apply a pod with a nodeSelector.
Bahasa Melayu
Pod (dulang) fast kata Pending. Ia tak pernah bermula. Apa yang ia tunggu?
fast.yaml bawa papan tanda. nodeSelector kata: “hanya node (gerai) dengan label ini.”
spec:
nodeSelector:
disk: ssdGerai mana boleh terima pod fast?
Letak setiap pod di atas gerai. Baca papan tanda dulu.
Itu kata-kata sebenar scheduler. Dalam bahasa mudah: satu gerai berkunci. Dua ada label salah. Tiada gerai bertanda disk=ssd.
Beri gerai dev-worker2 papan tanda itu. Pod yang menunggu patut masuk.
kubectl label nodes dev-worker2 disk=ssdNode affinity ialah senarai hajat: syarat wajib (required) dan syarat pilihan (preferred). Pod fast perlu ssd. Ia suka zon front. Asingkan kedua-duanya.
Dalam YAML, dua senarai itu nampak begini:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- { key: disk, operator: In, values: [ssd] }
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 50
preference:
matchExpressions:
- { key: zone, operator: In, values: [front] }
Pod fast berjalan di dev-worker2. Sekarang anda buang label itu: kubectl label nodes dev-worker2 disk-. Apa jadi pada pod itu?
Kini anda boleh hantar pod ke gerai yang betul dengan label.
You finished this before. Practice is always welcome!
Official docs: Kubernetes: assigning pods to nodes · Kubernetes: well-known labels · kubectl label
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?