Give nearby endpoints a larger share of traffic
Weight local endpoint groups by labels they share with the caller. The caller Dataplane and destination endpoint metadata must carry the listed keys. These groups share traffic by weight rather than acting as sequential failover targets.
Configuration
apiVersion: kuma.io/v1alpha1
kind: MeshLoadBalancingStrategy
metadata:
name: backend-local-affinity
namespace: kong-mesh-demo
labels:
kuma.io/mesh: default
spec:
to:
- targetRef:
kind: MeshService
labels:
kuma.io/display-name: backend
default:
localityAwareness:
localZone:
affinityTags:
- key: kubernetes.io/hostname
weight: 9000
- key: topology.kubernetes.io/zone
weight: 9Copied!
type: MeshLoadBalancingStrategy
name: backend-local-affinity
mesh: default
spec:
to:
- targetRef:
kind: MeshService
labels:
kuma.io/display-name: backend
default:
localityAwareness:
localZone:
affinityTags:
- key: kubernetes.io/hostname
weight: 9000
- key: topology.kubernetes.io/zone
weight: 9Copied!
Adjust konnect_mesh_control_plane.my_meshcontrolplane.id and konnect_mesh.my_mesh.name according to your current configuration.
resource "konnect_mesh_load_balancing_strategy" "backend_local_affinity" {
provider = konnect-beta
type = "MeshLoadBalancingStrategy"
name = "backend-local-affinity"
spec = {
to = [
{
target_ref = {
kind = "MeshService"
labels = {
"kuma.io/display-name" = "backend"
}
}
default = {
locality_awareness = {
local_zone = {
affinity_tags = [
{
key = "kubernetes.io/hostname"
weight = 9000
},
{
key = "topology.kubernetes.io/zone"
weight = 9
}
]
}
}
}
}
]
}
labels = {
"kuma.io/mesh" = konnect_mesh.my_mesh.name
}
cp_id = konnect_mesh_control_plane.my_meshcontrolplane.id
mesh = konnect_mesh.my_mesh.name
}
Copied!