Reputation: 2846
I have deployed AWS Load Balancer Controller on AWS EKS. I have created k8s Ingress resource I am deploying java web application with k8s Deployment. I want to make sure sticky session holds to make my application work.
I have read that if I set below annotation then sticky sessions will work :
alb.ingress.kubernetes.io/target-type: ip
But I am seeing ingress is routing requests to different replica each time letting login fail as session cookies are not persisting.
What am I missing here ?
Upvotes: 1
Views: 7152
Reputation: 740
Just to add a quick note, that although apparently possible, you should probably reevaluate your application's implementation if you are relying on sticky sessions in EKS. The pods may be killed off and recreated at any time, then sticky or not, your cookie is gone. Yes it will work most of the time, maybe that's good enough, but you should probably externalize anything you care about on other storage/database/redis etc
Upvotes: 0
Reputation: 30178
If you want to manage the stick session from the K8s level you can use the, sessionAffinity: ClientIP
kind: Service
apiVersion: v1
metadata:
name: service
spec:
selector:
app: app
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 10000
Upvotes: 0
Reputation: 15548
alb.ingress.kubernetes.io/target-type: ip
is required.
but the annotation to enable stickiness is:
alb.ingress.kubernetes.io/target-group-attributes: stickiness.enabled=true
Also you can set cookie_duration_settings
.
alb.ingress.kubernetes.io/target-group-attributes: stickiness.enabled=true,stickiness.lb_cookie.duration_seconds=300
Upvotes: 5