12.8 Session Affinity and Traffic Policies
Alright, let’s talk about how your Services actually decide which Pod gets the traffic. You’ve deployed your fancy, multi-Pod Deployment, exposed it with a Service, and you’re probably thinking, “Great, traffic will just spread out evenly!” And by default, you’d be right. But the real world is messy, and sometimes you need to bend that default behavior to your will. That’s where session affinity and traffic policies come in. The Default: A Fair-Weather Friend Out of the box, a standard ClusterIP or NodePort Service uses a completely stateless, round-robin load balancing algorithm across all ready Pods it selects. It’s the epitome of fairness. This is handled by kube-proxy on each node, either via iptables or IPVS rules. It’s simple, effective, and for most stateless workloads, it’s exactly what you want. But “most” isn’t “all.” The moment you need a user’s requests to consistently hit the same Pod—maybe because of an in-memory session, a cache, or some other sticky piece of state—this fairness becomes a problem.