Does sessionAffinity over ClientIP works with UDP protocol on Kubernetes setup?

8/27/2021

lets say, we have two independent Kubernetes clusters Cluster 1 & Cluster 2, Each of them has two replicas of same application Pod. Like Cluster 1 : Pod A & Pod B Cluster 2 : Pod C & Pod D Application code in Pod A(client) wants to connect to any Pod running in cluster 2 via NodePort/Loadbalancer service over UDP protocol to send messages. The only requirement is, to maintain affinity so that all messages from Pod A should go to any one pod only (either Pod C or Pod D). Since, UDP is a connectionless protocol, my concern is around the session Affinity based on ClientIP. Should setting the sessionAffinity as client IP solve my issue ?

-- Nish
kubernetes
kubernetes-helm
openshift
udp

1 Answer

8/27/2021

Since, UDP is a connectionless protocol, my concern is around the session Affinity based on ClientIP. Should setting the sessionAffinity as client IP solve my issue ?

sessionAffinity keeps each session based on sourceIP regardless of the protocols at the same cluster. But it does not mean your real session is kept as you expected on your env across your whole access path journey. In other words, just only using sessionAffinity does not ensure keeping whole session on your access paths.

For example, Pod A outbound IP is translated as running node IP(SNAT) if you does not use egress IP solutions for the Pod A. It also depends your NodePort and LoadBalancer Service config about source IP in cluster 2. Refer Using Source IP for more details.

So you should consider how to keep session safely while accessing each other between other clusters. Personally I think you had better consider application layer(7Layer) sticky session for keeping the session, not sessionAffinity of the service.

-- Daein Park
Source: StackOverflow