0
0
Kubernetesdevops~30 mins

Using labels for service routing in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Using labels for service routing
📖 Scenario: You are managing a Kubernetes cluster that runs multiple versions of a web application. You want to route traffic to the correct version using labels and services.
🎯 Goal: Create two deployments with different labels and a service that routes traffic to one of them using label selectors.
📋 What You'll Learn
Create a deployment named web-v1 with label version: v1
Create a deployment named web-v2 with label version: v2
Create a service named web-service that routes traffic to pods with label version: v1
Use correct Kubernetes YAML syntax for deployments and service
Verify the service routes to the correct pods by checking labels
💡 Why This Matters
🌍 Real World
In real Kubernetes clusters, labels and selectors help route traffic to the right pods, enabling blue-green deployments and canary releases.
💼 Career
Understanding labels and service routing is essential for Kubernetes administrators and DevOps engineers to manage application versions and traffic flow.
Progress0 / 4 steps
1
Create the first deployment with label
Create a deployment named web-v1 with label version: v1 and container image nginx:1.19. Use 2 replicas.
Kubernetes
Need a hint?

Use metadata.name for deployment name, spec.replicas for number of pods, and metadata.labels inside template for pod labels.

2
Create the second deployment with a different label
Create a deployment named web-v2 with label version: v2 and container image nginx:1.20. Use 2 replicas.
Kubernetes
Need a hint?

Follow the same structure as web-v1 deployment but change the name, label, and image.

3
Create a service to route traffic using label selector
Create a service named web-service that routes traffic to pods with label version: v1. Use port 80 for the service and target port 80 for the pods.
Kubernetes
Need a hint?

Use kind: Service with spec.selector matching version: v1 and define ports correctly.

4
Verify the service routes to the correct pods
Run the command kubectl get pods --selector=version=v1 --output=wide and print the output to verify pods with label version: v1 are selected.
Kubernetes
Need a hint?

Use print() to simulate the output of kubectl get pods --selector=version=v1 --output=wide.