Load Balancer Subsets
Subsets use the load balancer policy specified by the cluster. The original destination policy may not be used with subsets because the upstream hosts are not known in advance. Subsets are compatible with zone aware routing, but be aware that the use of subsets may easily violate the minimum hosts condition described above.
If subsets are configured and a route specifies no metadata or no subset matching the metadata exists, the subset load balancer initiates its fallback policy. The default policy is , in which case the request fails as if the cluster had no hosts. Conversely, the ANY_ENDPOINT
fallback policy load balances across all hosts in the cluster, without regard to host metadata. Finally, the causes fallback to load balance among hosts that match a specific set of metadata. It is possible to override fallback policy for specific subset selector.
Subsets must be predefined to allow the subset load balancer to efficiently select the correct subset of hosts. Each definition is a set of keys, which translates to zero or more subsets. Conceptually, each host that has a metadata value for all of the keys in a definition is added to a subset specific to its key-value pairs. If no host has all the keys, no subsets result from the definition. Multiple definitions may be provided, and a single host may appear in multiple subsets if it matches multiple definitions.
During routing, the route’s metadata match configuration is used to find a specific subset. If there is a subset with the exact keys and values specified by the route, the subset is used for load balancing. Otherwise, the fallback policy is used. The cluster’s subset configuration must, therefore, contain a definition that has the same keys as a given route in order for subset load balancing to occur.
Subsets can be configured with only a single host in each subset, which can be used in use cases similar to or ring hash, such as load balancing based on a cookie, but when it is important to select the same host even after new hosts are added to the cluster. Endpoint configuration changes may use less CPU if is enabled.
Host metadata is only supported when hosts are defined using ClusterLoadAssignments. ClusterLoadAssignments are available via EDS or the Cluster field. Host metadata for subset load balancing must be placed under the filter name "envoy.lb"
. Similarly, route metadata match criteria use filter name. Host metadata may be hierarchical (e.g., the value for a top-level key may be a structured value or list), but the subset load balancer only compares top-level keys and values. Therefore when using structured values, a route’s match criteria will only match if an identical structured value appears in the host’s metadata.
Finally, note that subset load balancing is not available for the CLUSTER_PROVIDED load balancer policies.
We’ll use simple metadata where all values are strings. Assume the following hosts are defined and associated with a cluster:
The cluster may enable subset load balancing like this:
The following table describes some routes and the result of their application to the cluster. Typically the match criteria would be used with routes matching specific aspects of the request, such as the path or header information.
Metadata match criteria may also be specified on a route’s weighted clusters. Metadata match criteria from the selected weighted cluster are merged with and override the criteria from the route:
An EDS LbEndpoint
with host metadata:
Example Route With Metadata Criteria
An RDS with metadata match criteria: