could you help with the Kubernetes NGINX Ingress controller? For one of our stateful applications, which receives requests from other backend services through the ingress, we need to organize load balancing with session affinity. We have configured the ingress using the username extracted from the JWT token (using a Lua script).
The load balancing strategy used is “nginx.ingress.kubernetes.io/upstream-hash-by: $original_user”. When running a load test where each user has a username such as username1, username2, … username10000, with this strategy on 2 pods, the majority of requests are directed to 1 of the pods. The number of requests to one pod exceeds the number of requests to the other by a huge margin, approximately 5 times.
Could you advise on how to achieve a more balanced distribution of load across the pods?
Here is our configuration for the ingress:
kind: Ingress
metadata:
name: redo-nuxeo
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |
set $original_user 'null';
access_by_lua_block {
local jwt_decoder = require "jwt_decoder"
jwt_decoder.get_original_user_from_jwt()
}
nginx.ingress.kubernetes.io/upstream-hash-by: $original_user
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
I tried hashing the usernames with MD5, SHA-256 before passing them to “nginx.ingress.kubernetes.io/upstream-hash-by: $original_user”, but this did not help.