Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Services and Networking  ›  Lesson

Services and Load Balancing

Load Balancing 12 minA Service gives a stable name and IP to a label-selected set of ready pods and spreads connections across them.

Services and Load Balancing

Three notes-web pods, three changing IPs, and clients that should not care about any of them. A Service is the one stable front door that hides the churn and spreads the traffic.

The rule

A Service is a stable name that spreads traffic across the pods its selector finds.

A Service has:

  • a selector — which pods it sends traffic to, by label;
  • a stable cluster IP that never changes while the Service exists;
  • a DNS name such as notes-web (inside the same namespace) or notes-web.notes.svc.cluster.local (from anywhere);
  • a port that clients use and a targetPort on the pods.
apiVersion: v1
kind: Service
metadata:
  name: notes-web
  namespace: notes
spec:
  selector:
    app: notes-web
  ports:
    - port: 80
      targetPort: 8080

Clients call http://notes-web:80. Kubernetes forwards each connection to port 8080 on one of the matching pods. The current list of pod addresses is kept in EndpointSlices, and kube-proxy on each node programs the rules that do the forwarding.

Only ready pods receive traffic. If a pod's readiness probe fails, it is removed from the list until it recovers. This is what makes rolling updates smooth.

Spreading is per connection, not per request. A client that keeps one long-lived connection open may stay with the same pod.

The shortcut

When a Service "doesn't work", check the three matches, left to right: name → selector → port.

notes-web returns connection refusedStep 1 of 4
  1. Name

    Is the client calling notes-web in the right namespace? From another namespace it needs notes-web.notes.

The most common cause of an empty Service is a selector that does not match the pod labels exactly — one character is enough.

Drills

Answer fast — trust the rule.

quick drill

A Service has port: 80 and targetPort: 8080. Which port do clients call?

quick drill

How does a Service find its pods?

quick drill

A pod's readiness probe is failing. What happens to Service traffic?

quick drill

From a pod in namespace tools, which name reaches the notes-web Service?

Remember

  • A Service is a stable name and IP that spreads traffic across the ready pods its selector finds.
  • Debug with the three matches: name → selector → port.
  • Trap: a one-character selector mismatch leaves the Service with no endpoints.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainDebug a Service

Clients get errors calling the notes-web Service. Describe, in order, the checks you would make, with the command or field you would look at for each.