0
0
Kubernetesdevops~30 mins

Annotations vs labels in Kubernetes - Hands-On Comparison

Choose your learning style9 modes available
Annotations vs Labels in Kubernetes
📖 Scenario: You are managing a Kubernetes cluster for a small company. You want to organize your pods by adding metadata that helps you identify and manage them easily.Labels and annotations are two ways to add metadata to Kubernetes objects. Labels are used for grouping and selecting objects, while annotations store additional information that is not used for selection.
🎯 Goal: Learn how to add labels and annotations to a Kubernetes pod manifest and understand the difference between them.
📋 What You'll Learn
Create a pod manifest with specific labels
Add annotations to the pod manifest
Use kubectl commands to view labels and annotations
Understand the difference between labels and annotations
💡 Why This Matters
🌍 Real World
In real Kubernetes clusters, labels help you group and manage resources easily, for example, to deploy updates or monitor specific sets of pods. Annotations provide extra information like build version or contact info that tools or humans can use.
💼 Career
Understanding labels and annotations is essential for Kubernetes administrators and DevOps engineers to organize, manage, and automate cluster resources effectively.
Progress0 / 4 steps
1
Create a Pod manifest with labels
Create a YAML file named pod.yaml with a pod named myapp-pod in the default namespace. Add the following labels under metadata.labels: app: myapp and env: production.
Kubernetes
Need a hint?

Labels go under metadata.labels as key-value pairs.

2
Add annotations to the Pod manifest
Add annotations under metadata.annotations in the same pod.yaml file. Add these exact annotations: description: "My application pod" and owner: "team-a".
Kubernetes
Need a hint?

Annotations go under metadata.annotations as key-value pairs, similar to labels.

3
Use kubectl to view labels and annotations
Run the command kubectl apply -f pod.yaml to create the pod. Then run kubectl get pod myapp-pod --show-labels to see the labels. Next, run kubectl describe pod myapp-pod and look for the annotations section.
Kubernetes
Need a hint?

Use kubectl apply to create the pod, kubectl get with --show-labels to see labels, and kubectl describe to see annotations.

4
Print the difference between labels and annotations
Write a command to print exactly this text: Labels are for grouping and selecting objects; annotations store additional metadata not used for selection.
Kubernetes
Need a hint?

Use echo with the exact text.