0
0
Kubernetesdevops~20 mins

Label selectors (equality, set-based) in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Label Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding equality-based label selectors

Which of the following label selectors will select pods with the label env exactly equal to production?

Aenv=production
Benv in (production)
Cenv!=production
Denv notin (production)
Attempts:
2 left
💡 Hint

Equality selectors use = or == to match exact label values.

💻 Command Output
intermediate
2:00remaining
Output of label selector with set-based syntax

Given the following pods with labels:

pod1: app=web, env=production
pod2: app=api, env=staging
pod3: app=web, env=staging
pod4: app=api, env=production

What pods will be selected by the label selector app in (web, api),env notin (staging)?

Apod2, pod3
Bpod1, pod4
Cpod1, pod2, pod3, pod4
Dpod3, pod4
Attempts:
2 left
💡 Hint

Look for pods where app is either web or api and env is not staging.

Configuration
advanced
2:30remaining
Correct label selector syntax in a Deployment spec

Which of the following spec.selector.matchLabels configurations is valid for selecting pods with label tier equal to frontend?

Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      labels:
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: nginx:latest
A
matchLabels:
  tier in (frontend)
B
matchLabels:
  tier == frontend
C
matchLabels:
  tier: frontend
D
matchLabels:
  tier != frontend
Attempts:
2 left
💡 Hint

In matchLabels, keys and values are simple key-value pairs without operators.

Troubleshoot
advanced
2:00remaining
Troubleshooting label selector syntax error

You apply this label selector in a kubectl get pods command:

kubectl get pods -l 'env notin production'

What error will you get?

Aerror: invalid label selector: 'env notin production' is not a valid selector
Berror: unknown flag: --notin
CNo pods returned, command runs successfully
DPods with label env=production are returned
Attempts:
2 left
💡 Hint

Check the syntax for set-based label selectors in kubectl commands.

🔀 Workflow
expert
3:00remaining
Selecting pods with multiple label conditions

You want to select pods that have label app equal to backend and label version either v1 or v2. Which label selector will correctly select these pods?

Aapp in (backend),version in (v1,v2)
Bapp==backend,version in (v1,v2)
Capp=backend,version=v1,version=v2
Dapp=backend,version in (v1,v2)
Attempts:
2 left
💡 Hint

Use equality for single value and set-based syntax for multiple values.