Sticky Session not working with Traefik v3

I have deployed Traefik v3.6.6 using Helm Chart v38.0.2 to Azure Kubernetes Cluster. HTTPRoute works fine but the moment sticky session is added to the Traefik Service, pods handle request in Round robin fashion and donot adhere to stickyness.

Below is the manifest file used:

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: myapp-httproute
spec:
  parentRefs:
  - name: traefik-gateway
    namespace: "myns"
  hostnames:
  - myapp.test.example.com
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    filters:
    - type: URLRewrite
      urlRewrite:
        path:
          type: ReplacePrefixMatch
          replacePrefixMatch: /
    backendRefs:
    - group: traefik.io
      kind: TraefikService
      name: myapp-sticky-session
---
apiVersion: traefik.io/v1alpha1
kind: TraefikService
metadata:
  name: myapp-sticky-session
spec:
  weighted:
    services:
      - name: myapp
        port: 80
        serversTransport: myapp-server-transport
    sticky:
      cookie:
        name: my_cookie
        maxAge: 360
        sameSite: none
        secure: true
        httpOnly: false
---
apiVersion: traefik.io/v1alpha1
kind: ServersTransport
metadata:
  name: myapp-server-transport
spec:
  forwardingTimeouts:
    dialTimeout: 3600s
    responseHeaderTimeout: 3600s
    idleConnTimeout: 1800s
---

I’ve tried multiple combinations

  • serversTransport is removed - did not work.
  • URLRewrite is removed - did not work.
  • sticky.cookie.httpOnly and sticky.cookie.secure is toggled - did not work.
  • Keeping only sticky.cookie.name - did not work.

First attempt to the service includes Cookie in the response header and for consecutive attempts Request Header has Cookie included. But sticky-ness is not maintained.

Traefik logs gives no errors. Although application works, the request is handled by different pods which breaks the overall flow.

As per the documentation sticky is at the same level as services, but it’s not working.

Below work-around gives better results.

Shifting stickyand its configuration to the right under the services section, i.e, making it as spec.weighted.services.sticky

Example:

apiVersion: traefik.io/v1alpha1
kind: TraefikService
metadata:
  name: myapp-sticky-session
spec:
  weighted:
    services:
      - name: myapp
        port: 80
        serversTransport: myapp-server-transport
		sticky:
		  cookie:
			name: my_cookie
			maxAge: 360
			sameSite: none
			secure: true
			httpOnly: false

However, the result is not 100%. On an average, 80% sticky session is maintained.

You checked the official docs [Basic, Advanced]?

Note there are two different examples for Gateway API and IngressRoute.

I have referred Advanced doc for configuring Sticky Session. I’m using Gateway API with Traefik Service, but it was not maintaining the sticky session.
Upon updating the Traefik Service as per the Ingress Route (sticky configuration inside the servcies section), I achieved 80% stickiness.