0
0
Kubernetesdevops~20 mins

Service selectors and labels in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Service Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Service Selectors in Kubernetes

What is the primary purpose of a selector in a Kubernetes Service?

ATo define the network port the Service listens on
BTo configure the storage volume attached to the Pods
CTo assign a unique IP address to the Service
DTo specify which Pods the Service should route traffic to based on matching labels
Attempts:
2 left
💡 Hint

Think about how a Service knows which Pods to send traffic to.

💻 Command Output
intermediate
1:30remaining
Output of kubectl get pods with label selector

Given the following Pods with labels:

pod1: app=web, env=prod
pod2: app=web, env=dev
pod3: app=db, env=prod

What is the output of the command kubectl get pods -l app=web,env=prod --no-headers -o custom-columns=:metadata.name?

Apod1
Bpod2
Cpod3
D
pod1
pod2
Attempts:
2 left
💡 Hint

The command filters Pods matching both labels app=web and env=prod.

Configuration
advanced
2:00remaining
Correct Service selector for multiple labels

You want to create a Service that routes traffic only to Pods labeled app=frontend and tier=production. Which selector configuration is correct?

A
selector:
  app: frontend
  tier: production
B
selector:
  app: frontend,tier: production
C
selector:
  app: frontend
  tier-production: true
D
selector:
  - app=frontend
  - tier=production
Attempts:
2 left
💡 Hint

Selectors use key-value pairs in YAML mapping format.

Troubleshoot
advanced
2:00remaining
Why does a Service not route traffic to Pods?

You created a Service with selector app: backend. However, no traffic reaches the Pods. The Pods have labels app: backend and version: v1. What is the most likely cause?

AThe Service type is ClusterIP, which cannot route traffic
BThe Pods are not running on the same node as the Service
CThe Service selector matches the Pods, but the Pods are not ready or have no endpoints
DThe Service selector does not match the Pod labels exactly due to a typo
Attempts:
2 left
💡 Hint

Check Pod readiness and endpoints associated with the Service.

🔀 Workflow
expert
2:30remaining
Order the steps to expose a Deployment using a Service with selectors

Arrange the steps in the correct order to expose a Deployment named myapp using a Service that routes traffic to its Pods via selectors.

A3,1,4,2
B1,3,2,4
C1,2,3,4
D2,1,3,4
Attempts:
2 left
💡 Hint

Think about creating resources and applying them in order.