Kubernetes : why are my requests redirected to different pods although I set sessionAffinity to ClientIP? Kubernetes : why are my requests redirected to different pods although I set sessionAffinity to ClientIP? kubernetes kubernetes

Kubernetes : why are my requests redirected to different pods although I set sessionAffinity to ClientIP?


When using headless service (clusterIP: None) you don't use proxy.

From k8s docs:

For headless Services, a cluster IP is not allocated, kube-proxy doesnot handle these Services, and there is no load balancing or proxyingdone by the platform for them. How DNS is automatically configureddepends on whether the Service has selectors defined

So when using headless service, dns responds with randomized list of ips of all pods associated with given service.

/app # dig service1 +search +short172.17.0.8172.17.0.10172.17.0.9/app # dig service1 +search +short172.17.0.9172.17.0.10172.17.0.8/app # dig service1 +search +short172.17.0.8172.17.0.10172.17.0.9/app # dig service1 +search +short172.17.0.10172.17.0.9172.17.0.8/app # dig service1 +search +short172.17.0.9172.17.0.8172.17.0.10

and curl just gets one and goes with it.

Since this hapens every request, every time you get different ip from dns, you connect to different pod.