0
0
Kubernetesdevops~20 mins

Adding labels to resources in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Label Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Adding a label to a running Pod
You have a running Pod named web-server. Which command will add the label env=production to this Pod without restarting it?
Akubectl edit pod web-server -l env=production
Bkubectl label pod web-server env=production
Ckubectl set label pod web-server env=production --overwrite
Dkubectl patch pod web-server -p '{"metadata":{"labels":{"env":"production"}}}'
Attempts:
2 left
💡 Hint
Use the kubectl command that adds labels directly to existing resources.
Configuration
intermediate
2:00remaining
Defining labels in a Deployment manifest
In a Kubernetes Deployment YAML, where should you add labels so that they apply to both the Deployment and the Pods it creates?
AUnder <code>metadata.labels</code> and <code>spec.template.metadata.labels</code>
BUnder <code>metadata.annotations</code> and <code>spec.template.metadata.annotations</code>
COnly under <code>spec.template.spec.containers.labels</code>
DOnly under <code>spec.selector.matchLabels</code>
Attempts:
2 left
💡 Hint
Labels must be on both the Deployment and Pod template to work properly.
Troubleshoot
advanced
2:00remaining
Why does a Pod not get selected by a Service after adding labels?
You added the label app=frontend to a Pod, but the Service with selector app=frontend does not route traffic to it. What is the most likely cause?
AThe Pod is in a different namespace than the Service
BThe Pod's labels were added after the Service was created and the Service cache is stale
CThe Service selector labels do not exactly match the Pod labels
DThe Pod's container ports are not exposed
Attempts:
2 left
💡 Hint
Check if the labels on the Pod exactly match the Service selector.
🔀 Workflow
advanced
2:00remaining
Labeling multiple resources efficiently
You want to add the label team=devops to all Pods in the namespace production. Which command achieves this in one step?
Akubectl label pods --selector=team=devops -n production
Bkubectl label pods -l team=devops -n production
Ckubectl label pods -n production team=devops
Dkubectl label pods --all team=devops -n production
Attempts:
2 left
💡 Hint
Use the flag that targets all Pods regardless of current labels.
Best Practice
expert
3:00remaining
Best practice for immutable labels on critical resources
You manage a critical Deployment and want to ensure its labels are not accidentally changed after creation. What is the best approach to enforce immutable labels?
AUse an admission controller webhook to reject label changes on the Deployment
BAdd labels only in Pod templates, not on the Deployment metadata
CManually monitor labels and revert changes with scripts
DUse annotations instead of labels for critical metadata
Attempts:
2 left
💡 Hint
Think about Kubernetes features that enforce policies automatically.