0
0
Kubernetesdevops~5 mins

Adding labels to resources in Kubernetes - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a label in Kubernetes?
A label is a key-value pair attached to Kubernetes objects like pods or services. It helps organize and select groups of resources easily.
Click to reveal answer
beginner
How do you add a label to a pod using kubectl command?
Use the command: <br>kubectl label pod <pod-name> key=value<br>This adds the label 'key=value' to the specified pod.
Click to reveal answer
intermediate
Can you add multiple labels at once? How?
Yes, add multiple labels by separating them with spaces:<br>kubectl label pod <pod-name> key1=value1 key2=value2
Click to reveal answer
beginner
Where do labels appear in a Kubernetes resource YAML file?
Labels appear under the metadata.labels section in the YAML file of the resource.
Click to reveal answer
beginner
Why are labels important in Kubernetes?
Labels help group and select resources for management, scaling, and monitoring. They make it easy to find and operate on sets of resources.
Click to reveal answer
Which command adds a label 'env=prod' to a pod named 'webapp'?
Akubectl apply label pod webapp env=prod
Bkubectl add label pod webapp env=prod
Ckubectl set label pod webapp env=prod
Dkubectl label pod webapp env=prod
Where in a Kubernetes YAML file do labels belong?
Ametadata.labels
Bspec.containers.labels
Cstatus.labels
Dspec.labels
What is the main purpose of labels in Kubernetes?
ATo group and select resources
BTo define resource limits
CTo store container images
DTo configure network policies
Can you add multiple labels in one kubectl label command?
ANo, only one label at a time
BYes, by separating with spaces
CYes, but only two labels max
DYes, by separating with commas
If you want to change a label value, what should you do?
AEdit the pod YAML and apply it without flags
BDelete the pod and recreate it
CUse kubectl label with the new value and --overwrite flag
DLabels cannot be changed once set
Explain how to add labels to a Kubernetes resource using kubectl.
Think about the command structure and how you specify labels.
You got /4 concepts.
    Describe why labels are useful in managing Kubernetes resources.
    Consider how labels help find and organize resources.
    You got /4 concepts.