I'm used to using Traefik, Docker, and K8S in a stateless environment. Recently I was assigned the mission to Dockerize an old Java app running on Tomcat. This app is stateful and doesn't share sessions, for now.
I have to put multiple instances of this app behind a reverse proxy that supports sticky sessions. I successfully implemented it with Traefik, but I want to go a step forward.
For now, Traefik has its own sticky-cookie. But it kinds of make a duplicate with the already existing JSESSIONID
set by Tomcat at the first request. Plus, the front is public and doesn't need sticky sessions, it is only needed when a user logs in.
I tried to set the label 'traefik.http.services.whoami-instance.loadBalancer.sticky.cookie.name=JSESSIONID'
but it breaks the sticky-session, and it goes back to some kind of roundrobin.
What I want to know is, is there a way to force Traefik to roundrobin when a specific cookie doesn't exist, say JSESSIONID
, and when the backend servers set that cookie, Traefik switches to sticky-session and forwards the requests to the same server ?
As always, thank you for your answers :)
Contents of the cookies are vastly different and they are not interchangeable.
A traefik cookie contains the url of the internal container eg. http://10.0.2.153:8080
whereas JSESSIONID contains an id value eg. DC57ABB53F4DE0BDCE7EE6FEFDFDFA97
Since traefik uses the content of the cookie to do routing, it is not possible to use another cookie that does not contain that information.