Hash load balancer in Kubernetes


We don’t have Kong Ingress installed, instead we are routing the traffic from the ingress to Kong and then to our service.
Our service has several pods that are not stateless and therefore we need session affinity.

We are trying to use the upstream hash_on_cookie but we get replies from different pods in each request.

We are not sure if this configuration is intended for our use case. If not, and as an alternative, would the Kong Ingress provide session affinity to the service pods?

Best regards,

When we configure session affinity with kubernetes ingress, e.g.:

kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/affinity: cookie
nginx.ingress.kubernetes.io/session-cookie-hash: sha1
nginx.ingress.kubernetes.io/session-cookie-name: INGRESSCOOKIE

We get a configuration in nginx.conf like:

upstream sticky-cookie-myapp-8080 {
    sticky cookie INGRESSCOOKIE hash=sha1;

    keepalive 32;

    server max_fails=0 fail_timeout=0;
    server max_fails=0 fail_timeout=0;


Is there something similar in Kong Ingress or the hash load balancer?

Kong can load balance based on your cookie data.

You can configure these using KongIngress Custom Resource.

Please also check out Kong’s documentation on how to configure Kong for various load balancing use cases: