Nginx Ingresses support consistent hashing, which can effectively resolve load balancing instability caused by dynamically adding or removing backend servers. This topic describes how to configure consistent hashing for NGINX Ingresses.
Background information
The source IP Hash method supported by NGINX Ingresses by default uses a linear hash space. The system selects the target backend server based on the hash value computed from the source IP address. This ensures that the same source IP is always routed to the same backend server.
However, this approach has an issue: when backend servers are added or removed, all source IPs must undergo re-hashing to adapt and reroute to the changed number of backend servers. This results in massive session disruption or cache invalidation.
To address the above issue, NGINX Ingresses introduce a consistent hashing algorithm. This algorithm replaces the conventional linear hash space with a ring-based hash space. When backend servers are added or removed, only a small portion of data (specifically, the segment adjacent to the added or removed server) requires rerouting. This approach effectively resolves load balancing disruption caused by dynamic scaling of backend servers.
Prerequisites
Procedure
Nginx Ingresses support consistent hashing for load balancing using annotations. The following file provides an example of NGINX Ingress configuration:
The following table describes the annotations.