Recall & Review
beginner
What is the purpose of labels in Kubernetes?
Labels are simple key-value pairs attached to Kubernetes objects. They help organize and select groups of objects for management and filtering.
Click to reveal answer
beginner
How do you list pods with a specific label using kubectl?
Use the command
kubectl get pods -l key=value to list pods that have the label with the specified key and value.Click to reveal answer
intermediate
What does the command
kubectl get pods -l env=prod,tier=frontend do?It lists pods that have both labels
env=prod and tier=frontend. Both conditions must be true for a pod to be shown.Click to reveal answer
intermediate
How can you filter Kubernetes objects by label existence, regardless of value?
Use
kubectl get pods -l key to select pods that have the label key, no matter what its value is.Click to reveal answer
intermediate
What is the difference between
-l key=value and -l 'key!=value' in kubectl?-l key=value selects objects with that exact label value. -l 'key!=value' selects objects where the label key exists but its value is not equal to the given value.Click to reveal answer
Which kubectl command lists pods with the label app=web?
✗ Incorrect
The correct syntax to filter by label is using
-l key=value.How do you select pods that have the label 'env' regardless of its value?
✗ Incorrect
Using
-l env selects pods that have the label key 'env' no matter the value.What does
kubectl get pods -l 'tier!=backend' do?✗ Incorrect
The != operator filters pods where the label exists but its value is not 'backend'.
How to filter pods with labels env=prod and tier=frontend at the same time?
✗ Incorrect
Multiple labels are combined with commas in the
-l option.Which command shows all pods without filtering by label?
✗ Incorrect
Running
kubectl get pods without -l shows all pods.Explain how to use kubectl to filter Kubernetes objects by labels. Include examples of filtering by single label, multiple labels, and label existence.
Think about how labels help select groups of objects.
You got /3 concepts.
Describe the difference between filtering with 'key=value' and 'key!=value' in kubectl label selectors.
Consider how the != operator changes the selection.
You got /2 concepts.