World map

 

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

You are here: cluster kind-dev namespace default
Three pods with their labels: api-1 has app=api, shop-1 has app=shop and tier=web, shop-2 has app=shop. Terminal output: $ kubectl get pods --show-labels NAME READY STATUS RESTARTS AGE LABELS api-1 1/1 Running 0 16s app=api shop-1 1/1 Running 0 16s app=shop,tier=web shop-2 1/1 Running 0 16s app=shop

A 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.

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
  • api-1
  • shop-2
dev-worker2Open
  • shop-1
Time: +0s (sped up)

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

Try it

Now do it with kubectl: kubectl label pod shop-2 tier=web. Then check with kubectl get pods -l tier=web.

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
  • api-1
  • shop-2
dev-worker2Open
  • shop-1
Time: +0s (sped up)

Check

Good label, or needs work? Swipe each one.

Swipe right for good, left for needs work. Or use the buttons.

1 / 4app=shop
app=shop

You 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

Pod template labels:
  • app=web

Labels

Real rep (optional): kubectl get pods -l app!=shop shows every tray without that sticker.