Locality awareness is on by default. A client prefers endpoints in its own zone, and moves to
lower-priority remote endpoints as local ones lose healthy capacity. The preference is based on endpoint
availability, not CPU or latency. To turn off the local-zone preference, set
localityAwareness.disabled: true.
localZone and crossZone still apply when disabled is set. To spread traffic across zones
without locality grouping, also remove any inherited localZone and crossZone
configuration.
localZone.affinityTags groups local endpoints by label values they share with the caller. For
each key, the control plane compares the caller Dataplane’s label value with endpoint
metadata. An endpoint joins the first group it matches. Groups share traffic by weight at the
same priority, instead of being tried in order on failure.
The following example prefers endpoints on the caller’s host, then endpoints in the same
infrastructure zone. Place it under a destination’s to[].default:
localityAwareness:
localZone:
affinityTags:
- key: kubernetes.io/hostname
- key: topology.kubernetes.io/zone
weight sets each group’s relative share. Without weights, they decrease tenfold down the
list: with two tags they’re 90 and 9, and unmatched local endpoints get 1. These are relative
weights, not fixed percentages. Set weights on all groups or none, because partial weights are
rejected.
The caller Dataplane must carry the label, and destination endpoint metadata must carry a
matching value. Endpoint metadata comes from resource labels or inbound tags. A key missing
from the caller creates no group, and a key that no endpoint has gets no traffic. Node labels
only work if they’re also in the workload’s Dataplane labels and endpoint metadata.
Explicit locality groups rebuild endpoint priorities and don’t keep remote fallback. If remote
endpoints must stay eligible, add a crossZone.failover list on a MeshMultiZoneService.
crossZone.failover lists, in priority order, the zones a client can reach when its local
endpoints aren’t enough. It’s only accepted when to[].targetRef.kind is
MeshMultiZoneService.
The following example lets clients in us-1 and us-2 fail over to those zones first, then
lets every client fail over to eu-1. Place it under to[].default for a
MeshMultiZoneService, and replace the zone names with zones where the service has endpoints:
localityAwareness:
crossZone:
failover:
- from:
zones: ["us-1", "us-2"]
to:
type: Only
zones: ["us-1", "us-2"]
- to:
type: Only
zones: ["eu-1"]
failoverThreshold:
percentage: 50
from.zones limits a rule to clients in those zones. Without it, the rule applies to every
zone. to.type selects the zones a rule sends traffic to:
|
to.type
|
Zones it selects
|
Only
|
The zones in to.zones, which can’t be empty.
|
AnyExcept
|
Every available zone except those in to.zones, which can’t be empty.
|
Any
|
Every available zone. to.zones must be empty.
|
None
|
No zone. to.zones must be empty.
|
A remote zone that no rule selects gets no traffic. Local endpoints always have the highest
priority. A zone named by several rules gets the first matching priority. None adds no
remote endpoints, but doesn’t cancel zones that another rule selects.
failoverThreshold.percentage sets when a priority has too little healthy capacity and traffic
starts moving to the next one. It defaults to 50: with ten endpoints in a priority, spillover
starts when fewer than five are healthy. Traffic can be shared between priorities during
degradation, instead of switching all at once.
The effective threshold can only be 100 divided by a whole number: 100%, 50%, 33.3%, 25%,
20%, and so on. Any other value is rounded up to the next one of these, so spillover starts
earlier than the value you set. For example, 30 behaves like 33.3%, and any value above
50, such as 70, behaves like 100%: spillover starts as soon as one endpoint in the
priority is unhealthy. 0 is rejected.
Endpoint health comes from MeshHealthCheck or
MeshCircuitBreaker outlier detection. Service discovery
can also remove endpoints, which changes the endpoint set that capacity is calculated against,
unlike marking an endpoint unhealthy. Test the failure you expect in production, because
scale-down and failed health checks can behave differently.