Full lesson
Explore the full explanation, examples, and visuals at your own pace.
Illustrative RPC counts per pod
All your traffic is hitting pod-a. The chart shows about twelve hundred RPCs per minute there, and zero on pod-b and pod-c. Three healthy replicas, one doing all the work. Adding more replicas won't change it, because the problem isn't capacity. It's how the connection gets chosen.
Chart values
| orders pods | RPCs per minute (illustrative) |
|---|---|
| pod-a | 1200 |
| pod-b | 0 |
| pod-c | 0 |
One connection, one pod
A ClusterIP Service balances at layer four. It picks a pod when a TCP connection opens, not per request. Here, orders-client opened just one connection to orders-svc, so orders-svc picked pod-a once. Every RPC rides that connection to pod-a, while pod-b and pod-c sit idle.
One pipe, many calls inside
Kubernetes balances connections, not calls. The kube-proxy gatekeeper picks a pod once, when the pipe opens. After that, every RPC from orders-client is just another capsule inside the same HTTP/2 connection, heading to pod-a, while the other two doors stay dark.
Streams multiplexed on one connection
Follow the timeline. orders-client opens a TCP connection, and kube-proxy NATs it to pod-a. That's the only moment a choice is made. After that, RPC 1, RPC 2, and RPC 3 are just new HTTP/2 streams, numbered 1, 3, and 5, on the same connection. No balancing decision ever happens again.
Fix step 1: headless Service
This is a second Service for the same pods. The key line is clusterIP: None. That removes the virtual IP, so there's nothing for kube-proxy to pin a connection to. Instead, DNS returns the IP of every ready pod, and the client can see pod-a, pod-b, and pod-c individually.
apiVersion: v1
kind: Service
metadata:
name: orders-svc-headless
spec:
clusterIP: None
selector:
app: orders
ports:
- port: 50051Fix step 2: client-side round_robin (grpc-go)
The dns:/// prefix tells grpc-go to resolve the headless name and collect every pod IP. The round_robin config then opens a subchannel to each one and rotates RPCs across them. Gotcha: the default is pick_first, which uses a single address. Older grpc-go versions call grpc.Dial instead.
conn, err := grpc.NewClient(
"dns:///orders-svc-headless:50051",
grpc.WithDefaultServiceConfig(
`{"loadBalancingConfig":[{"round_robin":{}}]}`),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)Other fixes and gotchas
You have other options. A proxy like Envoy or a mesh like Linkerd balances each RPC, with no client changes. MaxConnectionAge on the server forces periodic reconnects, spreading load coarsely. And new pods only receive traffic after the client re-resolves DNS.
- L7 proxy or mesh balances per RPC
- Server MaxConnectionAge forces periodic reconnects
- New pods need DNS re-resolution
Kubernetes balances connections; gRPC reuses one connection for every call.
Kubernetes balances connections; gRPC reuses one connection for every call. That's the whole mental model. So whenever gRPC traffic looks lopsided, ask where the balancing decision happens: once per connection, or once per request. Fix that, and orders-client reaches pod-a, pod-b, and pod-c evenly.
