Load balancing
Configure load balancing in ambient mesh — from ztunnel’s automatic L4 round-robin to advanced L7 policies via waypoint proxies.
Ambient mesh automatically load balances traffic across service backends. Ztunnel handles L4 load balancing with no additional configuration. For advanced L7 policies, add a waypoint proxy.
L4 load balancing
Ztunnel performs client-side load balancing for any destination service with multiple endpoints. The algorithm is a fixed L4 round-robin that distributes traffic based on connection state and is not user-configurable.
When a destination service has no waypoint, the source ztunnel load balances directly across the service’s pod endpoints and forwards traffic through the remote ztunnel on each destination node. When the destination service has a waypoint, the source ztunnel load balances across the waypoint proxy instances instead, and the waypoint handles traffic from there.
Prefer nearby endpoints
By default, ztunnel weights all endpoints equally. To prefer endpoints in the same region, zone, or cluster, set spec.trafficDistribution: PreferClose on the Service.
For ServiceEntry resources, or on older Kubernetes clusters that do not support the trafficDistribution field, set the networking.istio.io/traffic-distribution: PreferClose annotation on the Service instead.
Note
Traffic to waypoint proxies always uses PreferClose by default.
Configure L7 load balancing
When a service uses a waypoint proxy, you can configure advanced load balancing policies using a DestinationRule. By default, waypoints use a least-requests algorithm: each request goes to the host with fewer active requests, chosen from two randomly selected hosts in the pool.
The following additional algorithms are available:
- Random: Forward requests to a random instance in the pool.
- Weighted: Forward requests to instances according to a specific percentage.
- Round robin: Forward requests to each instance in sequence.
- Consistent hash: Provide soft session affinity based on HTTP headers, cookies, or other properties.
- Ring hash: Implement consistent hashing using the Ketama algorithm.
- Maglev: Implement consistent hashing as described in the Maglev paper.
For configuration details, see the Istio load balancing documentation and the Envoy load balancing documentation.
To favor endpoints based on topological location, see Locality load balancing.