Kubernetes · Orchestration under pressure
How does a Kubernetes Service route traffic to pods?
Short answer
A Service gives a stable virtual IP and DNS name to a set of pods selected by labels. EndpointSlices track ready pod IPs and the dataplane forwards traffic to them.
Pods come and go, so clients cannot rely on pod IPs. A Service selects pods with a label selector and gets a stable ClusterIP. The control plane maintains EndpointSlices containing the IPs of matching, ready pods, and kube-proxy or an eBPF dataplane programs the forwarding rules.
- Services select pods; they do not create them
- Only ready pods are normally included in endpoints
- The default protocol is TCP; UDP and SCTP are also supported
- Session affinity is optional and can skew load distribution
- A headless Service returns pod IPs directly for client-side discovery
apiVersion: v1
kind: Service
metadata:
name: api
spec:
selector:
app: api
ports:
- name: http
port: 80
targetPort: 8080The most common Service bug is a selector mismatch. If the Service has no endpoints, compare its selector with pod labels and confirm the pods are ready. A Service with zero endpoints will typically reject or time out connections rather than return a helpful error.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What happens if a Service selector matches no pods?
- 2Why do only ready pods appear in EndpointSlices?
- 3What is a headless Service used for?
- 4How would you debug a Service that times out?
Say it in the interview
A Service is a stable virtual IP and DNS name in front of a changing set of pods. It uses labels to select pods, and EndpointSlices track which pod IPs are ready. The dataplane then forwards traffic to those endpoints. When a Service fails, I check selector matches, endpoint readiness and target ports before looking at the application.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Kubernetes mock interview and get scored feedback on depth, clarity and confidence.