0
0
Kubernetesdevops~20 mins

Using labels for service routing in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Label Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Service routing with label selectors
Given the following Kubernetes service and pod labels, what pods will the service route traffic to?
Kubernetes
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: web
    tier: frontend
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080

Pods:
- pod1 labels: {app: web, tier: frontend}
- pod2 labels: {app: web, tier: backend}
- pod3 labels: {app: api, tier: frontend}
Apod1 only
Bpod1 and pod2
Cpod1 and pod3
Dpod2 and pod3
Attempts:
2 left
💡 Hint
The service selector matches pods with both labels 'app: web' and 'tier: frontend'.
🧠 Conceptual
intermediate
1:30remaining
Label importance in service routing
Why are labels important for Kubernetes service routing?
AThey store the service's IP address
BThey configure the service's port numbers
CThey specify the container image version
DThey define which pods receive traffic from the service
Attempts:
2 left
💡 Hint
Think about how a service knows which pods to send traffic to.
Configuration
advanced
2:00remaining
Correct label selector syntax
Which of the following service selector configurations correctly selects pods with label 'env=prod' and 'version=v2'?
Kubernetes
apiVersion: v1
kind: Service
metadata:
  name: example-service
spec:
  selector:
A
- env: prod
- version: v2
Benv=prod, version=v2
C
env: prod
version: v2
Denv: 'prod', version: 'v2'
Attempts:
2 left
💡 Hint
Look for the correct YAML key-value mapping under selector.
Troubleshoot
advanced
2:30remaining
Service routes no pods despite matching labels
A service selector is set to 'app: backend'. Pods have label 'app: backend'. However, the service routes no traffic. What is the most likely cause?
APods have the label but are not running
BPods are not in the same namespace as the service
CService port and pod targetPort do not match
DService type is ClusterIP instead of NodePort
Attempts:
2 left
💡 Hint
Check pod status and readiness.
🔀 Workflow
expert
3:00remaining
Label-based canary deployment routing
You want to route 10% of traffic to pods labeled 'version: canary' and 90% to 'version: stable' using Kubernetes services. Which approach achieves this?
AChange pod labels dynamically to switch 10% of pods to 'version: canary'
BCreate two services with selectors for each version and use an Ingress or external load balancer to split traffic by weight
CLabel all pods with both 'version: canary' and 'version: stable' and use one service
DUse a single service with selector 'version: canary, stable' to route traffic proportionally
Attempts:
2 left
💡 Hint
Kubernetes services do not support weighted routing by themselves.