0
0
Kubernetesdevops~30 mins

Adding labels to resources in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Adding labels to resources
📖 Scenario: You are managing a Kubernetes cluster for a small company. To organize and identify resources easily, you want to add labels to your pods. Labels help you group and select resources later.
🎯 Goal: Learn how to add labels to a Kubernetes pod manifest and verify the labels are applied correctly.
📋 What You'll Learn
Create a pod manifest with a specific name
Add a label to the pod metadata
Use kubectl commands to check the labels
Print the pod labels to confirm
💡 Why This Matters
🌍 Real World
Labels are used in Kubernetes to organize, select, and manage resources easily in real clusters.
💼 Career
Knowing how to add and use labels is essential for Kubernetes administrators and DevOps engineers to manage workloads efficiently.
Progress0 / 4 steps
1
Create a basic pod manifest
Create a YAML file named pod.yaml with a pod named myapp-pod in the default namespace. The pod should run the container image nginx.
Kubernetes
Need a hint?

Remember to include apiVersion, kind, metadata with name, and spec with containers.

2
Add a label to the pod metadata
Add a label called app with the value myapp under the metadata section in pod.yaml.
Kubernetes
Need a hint?

Labels go under metadata as a map of key-value pairs.

3
Apply the pod manifest and check labels
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 on the pod.
Kubernetes
Need a hint?

Use kubectl apply to create or update resources. Use kubectl get with --show-labels to see labels.

4
Print the pod labels using kubectl describe
Run kubectl describe pod myapp-pod and print the output to confirm the label app=myapp is present under Labels.
Kubernetes
Need a hint?

The kubectl describe command shows detailed info including labels under the Labels section.