Report this

What is the reason for this report?

Load Balancer Sticky Cookie (Kubernetes)

Posted on November 2, 2024

Hey so I have a load balancer setup with sticky cookies:

    service.beta.kubernetes.io/do-loadbalancer-sticky-sessions-type: "cookies"
    service.beta.kubernetes.io/do-loadbalancer-sticky-sessions-cookie-name: "storythreads-sticky-session"
    service.beta.kubernetes.io/do-loadbalancer-sticky-sessions-cookie-ttl: "3600" # 1 hr cookie duration; I assume its refreshed each time

A big problem I have though, is those cookies are set with SameSite=Lax - which means they cant be used in fetch requests cross origin.

I really need some way of changing that to None so that I can use fetches that have stickyness.

Any advice please?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi Ben,

As far as I can see from the DigitalOcean Managed Load Balancer documentation, sticky sessions are implemented at the load balancer layer. The cookies used for sticky sessions are set and stripped by the load balancer before the request reaches your backend application. This means that these cookies are not available to your backend applications, making them unsuitable for backend logic or cross-origin use cases.

As per the documentation:

  • Sticky session cookies are managed entirely by the load balancer.
  • They are stripped from the request before forwarding it to the backend, so they cannot be directly accessed or modified by your application.

Also on another note, Load Balancer sticky sessions only work with:

  • SSL termination (e.g., port 443 to port 80) or
  • HTTP requests (port 80 to port 80).

They do not work with SSL passthrough (port 443 to 443). Make sure your load balancer is terminating SSL and forwarding the request to your backend over HTTP or HTTPS for sticky sessions to function.

https://docs.digitalocean.com/glossary/sticky-session/#load-balancer

As you’re deploying on Kubernetes, using an ingress controller like NGINX Ingress gives you more control over cookies. For example, you can set cookie attributes directly in the ingress annotations:

https://docs.digitalocean.com/products/kubernetes/getting-started/operational-readiness/install-nginx-ingress-controller/

Let me know how it works for you!

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.