Skip to the page

Kubernetes: scaling and running it well · senior

Service balancing and long-lived connections

A ClusterIP Service balances connections, not requests. With HTTP/2 or gRPC one connection carries everything, so new pods can sit idle while old pods are overloaded.

The notes

What you must know

  • kube-proxy picks a backend pod when a connection opens. Every request on that connection goes to the same pod.
  • gRPC runs over HTTP/2, which sends all requests over one long-lived connection. Callers that connected when there were 3 pods never move to the 9 new pods.
  • Right now: a rolling restart of the callers makes them reconnect and spread out. This is only a stopgap; the next scale-up repeats it.
  • Fix on the server: set a maximum connection age with a grace period so clients reconnect regularly.
  • Fix on the client: a headless Service (clusterIP: None) so DNS returns every pod, and a round_robin policy. Or use a layer 7 proxy that balances each request (Envoy, Linkerd, Istio).
  • Same issue for keep-alive HTTP clients, database connection pools and WebSockets.
  • Verify: compare requests per second and CPU per pod. They should be similar.

The red pen

Common traps: mistake → fix

  • Mistake: A Service load-balances each request

    Fix: It balances connections. Long-lived connections stay on one pod.

  • Mistake: More replicas always lower the load of old pods

    Fix: Existing connections do not move.

  • Mistake: A headless Service balances traffic

    Fix: It returns pod addresses. The client must do the balancing.

Easy to hard

Questions interviewers ask, easy to hard

  1. How does a ClusterIP Service balance traffic?
  2. Why do new pods stay idle after a scale-up?
  3. What is a headless Service?
  4. How do you fix uneven gRPC load, now and permanently?
  5. How do you prove that load is uneven?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview