0
0
Kubernetesdevops~20 mins

Label-based filtering with kubectl in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Label Filtering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Filter pods by label with kubectl
You have several pods with labels: app=web and env=prod. Which command lists only pods with label app=web?
Akubectl get pods -l env=web
Bkubectl get pods --filter app=web
Ckubectl get pods -l app=web
Dkubectl get pods --label-selector env=prod
Attempts:
2 left
💡 Hint
Use the -l or --selector flag to filter by label.
💻 Command Output
intermediate
2:00remaining
Filter pods with multiple labels
Which command lists pods with labels app=web AND env=prod?
Akubectl get pods -l app=web,env=prod
Bkubectl get pods -l app=web; env=prod
Ckubectl get pods --selector app=web env=prod
Dkubectl get pods -l app=web env=prod
Attempts:
2 left
💡 Hint
Use commas to combine multiple labels in the selector.
Troubleshoot
advanced
2:00remaining
Why does this label filter return no pods?
You run kubectl get pods -l app=web env=prod but get no pods listed. Why?
AThere are no pods with label <code>app=web</code>.
BThe command syntax is incorrect; labels must be comma-separated with no spaces.
CThe <code>kubectl</code> version does not support label filtering.
DThe pods are in a different namespace.
Attempts:
2 left
💡 Hint
Check the label selector syntax carefully.
🧠 Conceptual
advanced
2:00remaining
Label selector operators in kubectl
Which label selector operator filters pods that have label env but its value is NOT prod?
Akubectl get pods -l 'env!=prod'
Bkubectl get pods -l 'env=prod'
Ckubectl get pods -l 'env in (prod)'
Dkubectl get pods -l 'env notin (prod)'
Attempts:
2 left
💡 Hint
Use the != operator to exclude a specific label value.
Best Practice
expert
2:00remaining
Efficiently watch pods with label changes
You want to watch pods with label app=web and get notified immediately when pods are added or removed. Which command is best?
Akubectl logs -l app=web --follow
Bkubectl describe pods -l app=web
Ckubectl get pods -l app=web --watch-only
Dkubectl get pods -l app=web --watch
Attempts:
2 left
💡 Hint
Use the watch flag to continuously monitor resource changes.