0
0
Kubernetesdevops~20 mins

Annotations vs labels in Kubernetes - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Annotations vs Labels Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose difference between labels and annotations

In Kubernetes, what is the main difference in purpose between labels and annotations?

ALabels are used for identifying and grouping objects; annotations store non-identifying metadata.
BLabels and annotations serve the same purpose and are interchangeable.
CAnnotations are used for grouping objects; labels store large amounts of metadata.
DAnnotations are only used for security settings; labels are for resource limits.
Attempts:
2 left
💡 Hint

Think about how Kubernetes selects objects versus storing extra info.

💻 Command Output
intermediate
2:00remaining
Output of kubectl get with labels and annotations

Given a pod with label app=web and annotation description=frontend, what is the output of kubectl get pods --show-labels?

Kubernetes
kubectl get pods --show-labels
A
NAME   READY   STATUS   RESTARTS   AGE   LABELS
mypod   1/1     Running  0          5m    
B
NAME   READY   STATUS   RESTARTS   AGE   LABELS
mypod   1/1     Running  0          5m    description=frontend
C
NAME   READY   STATUS   RESTARTS   AGE   LABELS
mypod   1/1     Running  0          5m    app=web
D
NAME   READY   STATUS   RESTARTS   AGE   LABELS
mypod   1/1     Running  0          5m    app=web,description=frontend
Attempts:
2 left
💡 Hint

Labels appear with --show-labels, annotations do not.

Configuration
advanced
2:00remaining
Correct YAML snippet for adding annotation and label

Which YAML snippet correctly adds a label tier=backend and an annotation owner=teamA to a pod spec?

A
metadata:
  labels:
    tier: backend
  annotations:
    owner: teamA
B
metadata:
  annotations:
    tier: backend
  labels:
    owner: teamA
C
metadata:
  labels:
    tier: backend
  owner: teamA
D
metadata:
  labels:
    tier: backend
  annotations:
    owner
Attempts:
2 left
💡 Hint

Labels and annotations are separate maps under metadata.

Troubleshoot
advanced
2:00remaining
Why does a label selector fail to find a pod?

You have a pod with annotation env=prod but no labels. You run kubectl get pods -l env=prod but get no results. Why?

AAnnotations must be lowercase to match selectors.
BThe pod must be restarted for labels to apply.
CAnnotations are automatically converted to labels but with delay.
DLabel selectors only match labels, not annotations.
Attempts:
2 left
💡 Hint

Think about what selectors use to find objects.

Best Practice
expert
2:00remaining
Choosing between labels and annotations for metadata

You want to store a large JSON string describing deployment details on a pod. Which is the best practice?

AUse labels because they are indexed and fast for queries.
BUse annotations because they can store large, non-identifying metadata.
CUse both labels and annotations to store the same data for redundancy.
DStore the JSON string in a ConfigMap and reference it in labels.
Attempts:
2 left
💡 Hint

Consider size limits and purpose of labels vs annotations.