0
0
Kubernetesdevops~30 mins

Service selectors and labels in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Service selectors and labels
📖 Scenario: You are managing a Kubernetes cluster for a small online store. You want to organize your pods and services so that the services can find the right pods using labels and selectors.
🎯 Goal: Learn how to create pods with labels and a service that selects those pods using matching labels.
📋 What You'll Learn
Create pods with specific labels
Create a service with a selector matching the pod labels
Verify the service selects the correct pods
💡 Why This Matters
🌍 Real World
Labels and selectors help organize and manage groups of pods in Kubernetes. Services use selectors to route traffic to the right pods automatically.
💼 Career
Understanding labels and selectors is essential for Kubernetes administrators and DevOps engineers to deploy and maintain scalable applications.
Progress0 / 4 steps
1
Create pods with labels
Create two pod YAML definitions named pod1.yaml and pod2.yaml. Each pod should have the label app: webstore. Use the image nginx for both pods.
Kubernetes
Need a hint?

Use metadata.labels to add labels to pods. Both pods must have the label app: webstore.

2
Create a service with a selector
Create a service YAML definition named service.yaml that selects pods with the label app: webstore. Use the service type ClusterIP and expose port 80.
Kubernetes
Need a hint?

Use spec.selector to match the label app: webstore. Set spec.type to ClusterIP and expose port 80.

3
Verify the service selects the pods
Write the kubectl command to list pods selected by the service webstore-service using the label selector app=webstore.
Kubernetes
Need a hint?

Use kubectl get pods -l app=webstore to list pods with the label app=webstore.

4
Display the pods selected by the service
Run the command kubectl get pods -l app=webstore and print the output exactly as it appears.
Kubernetes
Need a hint?

The output shows the pods with label app=webstore selected by the service.