Skip to content

How make sticky sessions path based for ALB, when using it in front of EKS

0

I am using an EKS cluster and direcly in front of it an ALB.

Now, there are many requests of the form https://my-domain.com/some-service/<document_id>, where document_id is varying.

Now, I would like to route traffic in EKS for document_id1 to pod1, for document_id2 to pod2, for document_id3 perhaps again to pod1 etc. In any case, I would like to send traffic for each fixed document_id to just one or at most a few pods in the Kubernetes cluster.

Is that or something similar possible by using sticky sessions for ALB? Or is there an alternative to it?

1 Answer
0

ALB sticky sessions cannot route based on path segments or document IDs. ALB stickiness uses cookies (AWSALB or AWSALBAPP) to bind a client to a target, not to route specific URL paths to specific backends. This means different clients requesting the same document_id will be routed to different pods, which does not meet your requirement. ALB target group routing algorithms (round robin, least outstanding requests, weighted random) do not support key-based or hash-based routing on request attributes. what you can do is adding a Consistent Hashing Layer. NGINX Ingress supports the nginx.ingress.kubernetes.io/upstream-hash-by annotation to hash requests based on request attributes. This ensures requests with the same document_id consistently route to the same pod. NGINX uses a hash ring algorithm, so scaling pods only remaps a fraction of keys rather than redistributing all traffic. Alternative: Istio/Envoy If using a service mesh, configure Istio's DestinationRule with consistentHash on a request header or URI parameter. Istio supports ring hash and Maglev algorithms. some design consideration: If your requirement is driven by per-document state stored in pods, consider externalizing state to ElastiCache (Redis) or DynamoDB instead. This eliminates the need for affinity and makes your application resilient to pod restarts and scaling events.

answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.