Question

Load Balancer Sticky Cookie (Kubernetes)

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?


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
December 5, 2024

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.