BM: Baca dalam Bahasa Melayu
World K1: The Food Court
Labels and selectors
You will learn: how labels tag your pods, and how selectors pick them.
Checked with Kubernetes 1.37 on 31 Oct 2026
The problem
Your food court has 20 trays: shop trays and api trays. The shop’s order number must reach only shop trays. How does it find them?
Pick one answer.
Watch
kind-dev namespace defaultA label: A sticker on a tray: a key and a value, like app=shop. is a sticker: a key and a value, like app=shop. A tray can wear many. --show-labels shows them.
Try it
A selector: A rule that picks trays by their stickers, like app=shop. picks trays by their stickers. Show only the shop trays: kubectl get pods -l app=shop.
kind-dev namespace defaultdev-control-planeOpenManagerNo trays here.
dev-workerOpen- api-1
- shop-2
dev-worker2Open- shop-1
Hint
-l means label selector.Predict
Which pods match -l app=shop,tier=web?
Pick one answer.
Try it
The order number shop picks app=shop and tier=web. Stick labels so both shop trays answer, and api-1 does not.
Drag a label onto a tray, or tap a label, then a tray.
Service shop (order number)
selector:app=shoptier=web
Picks 1 trays.
Labels
shop-1
- app=shop
- tier=web
shop picks this tray.
shop-2
- app=shop
Not picked: needs tier=web.
api-1
- app=api
Not picked: needs app=shop.
kubectl get endpointslices -l kubernetes.io/service-name=shopNAME ADDRESSTYPE PORTS ENDPOINTS AGEshop-2jl8t IPv4 80 10.244.1.84 12s
Hint
shop-2 is missing one sticker.Try it
Now do it with kubectl: kubectl label pod shop-2 tier=web. Then check with kubectl get pods -l tier=web.
kind-dev namespace defaultdev-control-planeOpenManagerNo trays here.
dev-workerOpen- api-1
- shop-2
dev-worker2Open- shop-1
Check
Good label, or needs work? Swipe each one.
Swipe right for good, left for needs work. Or use the buttons.
app=shopYou did it!
You can now stick labels on trays and pick them with selectors.
Go deeper (optional)
Deployments use selectors too. Their pod template must wear the labels the selector asks for. Try it:
Give the pod template labels that match the selector. Then press Apply.
Deployment shop (standing order)
selector:app=shop
- app=web
Labels
Real rep (optional): kubectl get pods -l app!=shop shows every tray without that sticker.
Bahasa Melayu
Medan selera anda ada 20 dulang: dulang shop dan dulang api. Nombor pesanan shop mesti sampai ke dulang shop sahaja. Macam mana ia cari?
Label (pelekat) ialah pelekat: satu kunci dan satu nilai, contohnya app=shop. Satu dulang boleh pakai banyak. --show-labels tunjuk semuanya.
Selector (pemilih) pilih dulang ikut pelekatnya. Tunjuk dulang shop sahaja: kubectl get pods -l app=shop.
-l bermaksud label selector.Pod mana yang padan dengan -l app=shop,tier=web?
Nombor pesanan shop pilih app=shop dan tier=web. Lekatkan label supaya kedua-dua dulang shop menjawab, tapi api-1 tidak.
Sekarang buat dengan kubectl: kubectl label pod shop-2 tier=web. Kemudian semak dengan kubectl get pods -l tier=web.
Label yang baik, atau perlu diperbaiki? Leret setiap satu.
Kini anda boleh lekatkan label pada dulang dan pilihnya dengan selector.
You finished this before. Practice is always welcome!
Official docs: Labels and selectors · kubectl label
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?