I have a Kubernetes application that acts as a HTTP proxy to a remote device.
The work flow is the that the remote device opens a websocket connection to the application, then any requests on a specific route gets forwarded over the websocket to the device to respond. This works really well when there is a single instance of the web app.
When we need to scale to 2 instances of the web app, we add Sticky Session annotations on an extra k8s service which just covers the route prefix used for the websocket and the proxy route
traefik.ingress.kubernetes.io/service.sticky.cookie: "true"
traefik.ingress.kubernetes.io/service.sticky.cookie.name: FFSESSION
traefik.ingress.kubernetes.io/service.sticky.cookie.path: /d
e.g. /d to match /d/:deviceId/ws and /d/:deviceId/proxy/*
We have the device report back it's sticky session cookie to the web app and then have the web app set the same cookie for the browser on the path /d/:deviceId.
This ends up with the the browser having 2 cookies set.
- first by Traefik for the
/dpath - second by the browser for
/d/:deviceId
The browser appears to follow spec and sort by longest path first so the cookies are sent with the value matching the device first and then the generic one.
This all appears to work, but I just want to clarify that when processing Sticky Session cookies Traefik will always use the first cookie in the header?
The next problem is how to handle restarting the web app, because this kicks the device off, it reconnects and pushes the new cookie value need to handle changing the browser cookie quickly enough to keep it all running.