Skip to content
Kong Logo | Kong Docs Logo
  • Docs
    • Explore the API Specs
      View all API Specs View all API Specs View all API Specs arrow image
    • Documentation
      API Specs
      Kong Gateway
      Lightweight, fast, and flexible cloud-native API gateway
      Kong Konnect
      Single platform for SaaS end-to-end connectivity
      Kong AI Gateway
      Multi-LLM AI Gateway for GenAI infrastructure
      Kong Mesh
      Enterprise service mesh based on Kuma and Envoy
      decK
      Helps manage Kong’s configuration in a declarative fashion
      Kong Ingress Controller
      Works inside a Kubernetes cluster and configures Kong to proxy traffic
      Kong Gateway Operator
      Manage your Kong deployments on Kubernetes using YAML Manifests
      Insomnia
      Collaborative API development platform
  • Plugin Hub
    • Explore the Plugin Hub
      View all plugins View all plugins View all plugins arrow image
    • Functionality View all View all arrow image
      View all plugins
      AI's icon
      AI
      Govern, secure, and control AI traffic with multi-LLM AI Gateway plugins
      Authentication's icon
      Authentication
      Protect your services with an authentication layer
      Security's icon
      Security
      Protect your services with additional security layer
      Traffic Control's icon
      Traffic Control
      Manage, throttle and restrict inbound and outbound API traffic
      Serverless's icon
      Serverless
      Invoke serverless functions in combination with other plugins
      Analytics & Monitoring's icon
      Analytics & Monitoring
      Visualize, inspect and monitor APIs and microservices traffic
      Transformations's icon
      Transformations
      Transform request and responses on the fly on Kong
      Logging's icon
      Logging
      Log request and response data using the best transport for your infrastructure
  • Support
  • Community
  • Kong Academy
Get a Demo Start Free Trial
Kong Mesh
2.5.x
  • Home icon
  • Kong Mesh
  • Policies
  • MeshLoadBalancingStrategy
github-edit-pageEdit this page
report-issueReport an issue
  • Kong Gateway
  • Kong Konnect
  • Kong Mesh
  • Kong AI Gateway
  • Plugin Hub
  • decK
  • Kong Ingress Controller
  • Kong Gateway Operator
  • Insomnia
  • Kuma

  • Docs contribution guidelines
  • dev
  • 2.10.x (latest)
  • 2.9.x
  • 2.8.x
  • 2.7.x (LTS)
  • 2.6.x
  • 2.5.x
  • 2.4.x
  • 2.3.x
  • 2.2.x
  • Introduction
    • About service meshes
    • Overview of Kong Mesh
    • How Kong Mesh works
    • Architecture
    • Stages of software availability
    • Version support policy
    • Mesh requirements
    • Release notes
  • Getting Started
  • Kong Mesh in Production
    • Overview
    • Deployment topologies
      • Overview
      • Standalone deployment
      • Multi-zone deployment
    • Install kumactl
    • Use Kong Mesh
    • Control plane deployment
      • Kong Mesh license
      • Deploy a standalone control plane
      • Deploy a multi-zone global control plane
      • Zone Ingress
      • Zone Egress
      • Configure zone proxy authentication
      • Control plane configuration reference
      • Systemd
      • Kubernetes
    • Create multiple service meshes in a cluster
    • Data plane configuration
      • Data plane proxy
      • Configure the data plane on Kubernetes
      • Configure the data plane on Universal
      • Configure the Kong Mesh CNI
      • Configure transparent proxying
      • IPv6 support
    • Secure your deployment
      • Manage secrets
      • Authentication with the API server
      • Authentication with the data plane proxy
      • Configure data plane proxy membership
      • Secure access across services
      • Kong Mesh RBAC
      • FIPS support
    • Kong Mesh user interface
    • Upgrades and tuning
      • Upgrade Kong Mesh
      • Performance fine-tuning
  • Deploy
    • Explore Kong Mesh with the Kubernetes demo app
    • Explore Kong Mesh with the Universal demo app
  • Explore
    • Gateway
      • Delegated
      • Builtin
    • CLI
      • kumactl
    • Observability
      • Demo setup
      • Control plane metrics
      • Configuring Prometheus
      • Configuring Grafana
      • Configuring Datadog
      • Observability in multi-zone
    • Inspect API
      • Matched policies
      • Affected data plane proxies
      • Envoy proxy configuration
    • Kubernetes Gateway API
      • Installation
      • Gateways
      • TLS termination
      • Customization
      • Multi-mesh
      • Multi-zone
      • GAMMA
      • How it works
  • Networking
    • Service Discovery
    • DNS
      • How it works
      • Installation
      • Configuration
      • Usage
    • Non-mesh traffic
      • Incoming
      • Outgoing
    • Transparent Proxying
  • Monitor & manage
    • Dataplane Health
      • Circuit Breaker Policy
      • Kubernetes and Universal Service Probes
      • Health Check Policy
    • Control Plane Configuration
      • Modifying the configuration
      • Inspecting the configuration
      • Store
  • Policies
    • Introduction
    • General notes about Kong Mesh policies
    • Applying Policies
    • How Kong Mesh chooses the right policy to apply
    • Understanding TargetRef policies
    • Protocol support in Kong Mesh
    • Mutual TLS
      • Usage of "builtin" CA
      • Usage of "provided" CA
      • Permissive mTLS
      • Certificate Rotation
    • Traffic Permissions
      • Usage
      • Access to External Services
    • Traffic Route
      • Usage
    • Traffic Metrics
      • Expose metrics from data plane proxies
      • Expose metrics from applications
      • Override Prometheus settings per data plane proxy
      • Filter Envoy metrics
      • Secure data plane proxy metrics
    • Traffic Trace
      • Add a tracing backend to the mesh
      • Add TrafficTrace resource
    • Traffic Log
      • Add a logging backend
      • Add a TrafficLog resource
      • Logging external services
      • Builtin Gateway support
      • Access Log Format
    • Locality-aware Load Balancing
      • Enabling locality-aware load balancing
    • Fault Injection
      • Usage
      • Matching
    • Health Check
      • Usage
      • Matching
    • Circuit Breaker
      • Usage
      • Matching
      • Builtin Gateway support
      • Non-mesh traffic
    • External Service
      • Usage
      • Builtin Gateway support
    • Retry
      • Usage
      • Matching
      • Builtin Gateway support
    • Timeout
      • Usage
      • Configuration
      • Default general-purpose Timeout policy
      • Matching
      • Builtin Gateway support
      • Inbound timeouts
      • Non-mesh traffic
    • Rate Limit
      • Usage
      • Matching destinations
      • Builtin Gateway support
    • Virtual Outbound
      • Examples
    • MeshGateway
      • TLS Termination
    • MeshGatewayRoute
      • Listener tags
      • Matching
      • Filters
      • Reference
    • MeshGatewayInstance
    • Service Health Probes
      • Kubernetes
      • Universal probes
    • MeshAccessLog
      • TargetRef support matrix
      • Configuration
      • Examples
    • MeshCircuitBreaker
      • TargetRef support matrix
      • Configuration
      • Examples
    • MeshFaultInjection
      • TargetRef support matrix
      • Configuration
      • Examples
    • MeshHealthCheck
      • TargetRef support matrix
      • Configuration
      • Examples
    • MeshHTTPRoute
      • TargetRef support matrix
      • Configuration
      • Examples
      • Merging
    • MeshProxyPatch
      • TargetRef support matrix
      • Configuration
      • Examples
      • Merging
    • MeshRateLimit
      • TargetRef support matrix
      • Configuration
      • Examples
    • MeshRetry
      • TargetRef support matrix
      • Configuration
      • Examples
    • MeshTCPRoute
      • TargetRef support matrix
      • Configuration
      • Examples
      • Route policies with different types targeting the same destination
    • MeshTimeout
      • TargetRef support matrix
      • Configuration
      • Examples
    • MeshTrace
      • TargetRef support matrix
      • Configuration
      • Examples
    • MeshTrafficPermission
      • TargetRef support matrix
      • Configuration
      • Examples
    • MeshLoadBalancingStrategy
      • TargetRef support matrix
      • Configuration
      • Examples
    • OPA policy
    • MeshOPA (beta)
    • MeshGlobalRateLimit (beta)
  • Enterprise Features
    • Overview
    • HashiCorp Vault CA
    • Amazon ACM Private CA
    • cert-manager Private CA
    • OPA policy support
    • MeshOPA (beta)
    • Multi-zone authentication
    • FIPS support
    • Certificate Authority rotation
    • Role-Based Access Control
    • Red Hat
      • UBI Images
      • Red Hat OpenShift Quickstart
    • Windows Support
    • ECS Support
    • Auditing
    • MeshGlobalRateLimit (beta)
  • Reference
    • HTTP API
    • Kubernetes annotations and labels
    • Kuma data collection
    • Control plane configuration reference
    • Envoy proxy template
  • Community
    • Contribute to Kuma
enterprise-switcher-icon Switch to OSS
On this pageOn this page
  • TargetRef support matrix
  • Configuration
    • LocalityAwareness
    • LoadBalancer
  • Examples
    • RingHash load balancing from web to backend
    • Disable locality-aware load balancing for backend
    • Disable cross zone traffic and prioritize traffic the dataplanes on the same node and availability zone
    • Disable cross zone traffic and route to the local zone instances equally
    • Route within the local zone equally, but specify cross zone order
    • Prioritize traffic to data planes within the same data center and fallback cross zone in specific order
  • Load balancing HTTP traffic through zone proxies
  • All policy options
You are browsing documentation for an older version. See the latest documentation here.

MeshLoadBalancingStrategy

This policy uses new policy matching algorithm.

This policy enables Kong Mesh to configure the load balancing strategy for traffic between services in the mesh. When using this policy, the localityAwareLoadBalancing flag is ignored.

TargetRef support matrix

TargetRef type top level to from
Mesh ✅ ✅ ❌
MeshSubset ✅ ❌ ❌
MeshService ✅ ✅ ❌
MeshServiceSubset ✅ ❌ ❌

To learn more about the information in this table, see the matching docs.

Configuration

LocalityAwareness

Locality-aware load balancing provides robust and straightforward method for balancing traffic within and across zones. This not only allows you to route traffic across zones when the local zone service is unhealthy but also enables you to define traffic prioritization within the local zone and set cross-zone fallback priorities.

Default behaviour

Locality-aware load balancing is enabled by default, unlike its predecessor localityAwareLoadBalancing. Requests are distributed across all endpoints within the local zone first unless there are not enough healthy endpoints.

Disabling locality aware routing

If you do so, all endpoints regardless of their zone will be treated equally. To do this do:

localityAwareness:
  disabled: true

Configuring LocalityAware Load Balancing for traffic within the same zone

If crossZone and/or localZone is defined, they take precedence over disabled and apply more specific configuration.

Local zone routing allows you to define traffic routing rules within a local zone, prioritizing data planes based on tags and their associated weights. This enables you to allocate specific traffic percentages to data planes with particular tags within the local zone. If there are no healthy endpoints within the highest priority group, the next priority group takes precedence. Locality awareness within the local zone relies on tags within inbounds, so it’s crucial to ensure that the tags used in the policy are defined for the service (Dataplane object on Universal, PodTemplate labels on Kubernetes).

  • localZone - (optional) allows to define load balancing priorities between dataplanes in the local zone. When not defined, traffic is distributed equally to all endpoints within the local zone.
    • affinityTags - list of tags and their weights based on which traffic is load balanced
      • key - defines tag for which affinity is configured. The tag needs to be configured on the inbound of the service. In case of Kubernetes, pod needs to have a label. On Universal user needs to define it on the inbound of the service. If the tag is absent this entry is skipped.
      • weight - (optional) weight of the tag used for load balancing. The bigger the weight the higher number of requests is routed to dataplanes with specific tag. By default we will adjust them so that 90% traffic goes to first tag, 9% to next, and 1% to third and so on.

Configuring LocalityAware Load Balancing for traffic across zones

Remember that cross-zone traffic requires mTLS to be enabled.

Advanced locality-aware load balancing provides a powerful means of defining how your service should behave when there is no instances of your service available or they are in a degraded state in your local zone. With this feature, you have the flexibility to configure the fallback behavior of your service, specifying the order in which it should attempt fallback options and defining different behaviors for instances located in various zones.

  • crossZone - (optional) allows to define behaviour when there is no healthy instances of the service. When not defined, cross zone traffic is disabled.
    • failover - defines a list of load balancing rules in order of priority. If a zone is not specified explicitly by name or implicitly using the type Any/AnyExcept it is excluded from receiving traffic. By default, the last rule is always None which means, that there is no traffic to other zones after specified rules.
      • from - (optional) defines the list of zones to which the rule applies. If not specified, rule is applied to all zones.
        • zones - list of zone names.
      • to - defines to which zones the traffic should be load balanced.
        • type - defines how target zones will be picked from available zones. Available options:
          • Any - traffic will be load balanced to every available zone.
          • Only - traffic will be load balanced only to zones specified in zones list.
          • AnyExcept - traffic will be load balanced to every available zone except those specified in zones list.
          • None - traffic will not be load balanced to any zone.
        • zones - list of zone names
    • failoverThreshold.percentage - (optional) defines the percentage of live destination data plane proxies below which load balancing to the next priority starts. .e.g: If you have this set to 70 and you have 10 data plane proxies it will start load balancing to the next priority when the number of healthy destinations falls under 7. The value to be in (0.0 - 100.0] range (Default 50). If the value is a double number, put it in quotes.

Zone Egress support

Using Zone Egress Proxy in multizone deployment poses certain limitations for this feature. When configuring MeshLoadbalancingStrategy with Zone Egress you can only use Mesh as a top level targetRef. This is because we don’t differentiate requests that come to Zone Egress from different clients, yet.

Moreover, Zone Egress is a simple proxy that uses long-lived L4 connection with each Zone Ingresses. Consequently, when a new MeshLoadbalancingStrategy with locality awareness is configured, connections won’t be refreshed, and locality awareness will apply only to new connections.

Another thing you need to be aware of is how outbound traffic behaves when you use the MeshCircuitBreaker’s outlier detection to keep track of healthy endpoints. Normally, you would use MeshCircuitBreaker to act on failures and trigger traffic redirect to the next priority level if the number of healthy endpoints fall below crossZone.failoverThreshold. When you have a single instance of Zone Egress, all remote zones will be behind a single endpoint. Since MeshCircuitBreaker is configured on Data Plane Proxy, when one of the zones start responding with errors it will mark the whole Zone Egress as not healthy and won’t send traffic there even though there could be multiple zones with live endpoints. This will be changed in the future with overall improvements to the Zone Egress proxy.

LoadBalancer

  • type - available values are RoundRobin, LeastRequest, RingHash, Random, Maglev.

RoundRobin

RoundRobin is a load balancing algorithm that distributes requests across available upstream hosts in round-robin order.

LeastRequest

LeastRequest selects N random available hosts as specified in choiceCount (2 by default) and picks the host which has the fewest active requests.

  • choiceCount - (optional) is the number of random healthy hosts from which the host with the fewest active requests will be chosen. Defaults to 2 so that Envoy performs two-choice selection if the field is not set.

RingHash

RingHash implements consistent hashing to upstream hosts. Each host is mapped onto a circle (the “ring”) by hashing its address; each request is then routed to a host by hashing some property of the request, and finding the nearest corresponding host clockwise around the ring.

  • hashFunction - (optional) available values are XX_HASH, MURMUR_HASH_2. Default is XX_HASH.
  • minRingSize - (optional) minimum hash ring size. The larger the ring is (that is, the more hashes there are for each provided host) the better the request distribution will reflect the desired weights. Defaults to 1024 entries, and limited to 8M entries.
  • maxRingSize - (optional) maximum hash ring size. Defaults to 8M entries, and limited to 8M entries, but can be lowered to further constrain resource use.
  • hashPolicies - (optional) specify a list of request/connection properties that are used to calculate a hash. These hash policies are executed in the specified order. If a hash policy has the “terminal” attribute set to true, and there is already a hash generated, the hash is returned immediately, ignoring the rest of the hash policy list.
    • type - available values are Header, Cookie, Connection, QueryParameter, FilterState
    • terminal - is a flag that short-circuits the hash computing. This field provides a ‘fallback’ style of configuration: “if a terminal policy doesn’t work, fallback to rest of the policy list”, it saves time when the terminal policy works. If true, and there is already a hash computed, ignore rest of the list of hash polices.
    • header:
      • name - the name of the request header that will be used to obtain the hash key.
    • cookie:
      • name - the name of the cookie that will be used to obtain the hash key.
      • ttl - (optional) if specified, a cookie with this time to live will be generated if the cookie is not present.
      • path - (optional) the name of the path for the cookie.
    • connection:
      • sourceIP - if true, then hashing is based on a source IP address.
    • queryParameter:
      • name - the name of the URL query parameter that will be used to obtain the hash key. If the parameter is not present, no hash will be produced. Query parameter names are case-sensitive.
    • filterState:
      • key the name of the Object in the per-request filterState, which is an Envoy::Hashable object. If there is no data associated with the key, or the stored object is not Envoy::Hashable, no hash will be produced.

Random

Random selects a random available host. The random load balancer generally performs better than round-robin if no health checking policy is configured. Random selection avoids bias towards the host in the set that comes after a failed host.

Maglev

Maglev implements consistent hashing to upstream hosts. Maglev can be used as a drop in replacement for the ring hash load balancer any place in which consistent hashing is desired.

  • tableSize - (optional) the table size for Maglev hashing. Maglev aims for “minimal disruption” rather than an absolute guarantee. Minimal disruption means that when the set of upstream hosts change, a connection will likely be sent to the same upstream as it was before. Increasing the table size reduces the amount of disruption. The table size must be prime number limited to 5000011. If it is not specified, the default is 65537.
  • hashPolicies - (optional) specify a list of request/connection properties that are used to calculate a hash. These hash policies are executed in the specified order. If a hash policy has the “terminal” attribute set to true, and there is already a hash generated, the hash is returned immediately, ignoring the rest of the hash policy list.
    • type - available values are Header, Cookie, Connection, QueryParameter, FilterState
    • terminal - is a flag that short-circuits the hash computing. This field provides a ‘fallback’ style of configuration: “if a terminal policy doesn’t work, fallback to rest of the policy list”, it saves time when the terminal policy works. If true, and there is already a hash computed, ignore rest of the list of hash polices.
    • header:
      • name - the name of the request header that will be used to obtain the hash key.
    • cookie:
      • name - the name of the cookie that will be used to obtain the hash key.
      • ttl - (optional) if specified, a cookie with this time to live will be generated if the cookie is not present.
      • path - (optional) the name of the path for the cookie.
    • connection:
      • sourceIP - if true, then hashing is based on a source IP address.
    • queryParameter:
      • name - the name of the URL query parameter that will be used to obtain the hash key. If the parameter is not present, no hash will be produced. Query parameter names are case-sensitive.
    • filterState:
      • key the name of the Object in the per-request filterState, which is an Envoy::Hashable object. If there is no data associated with the key, or the stored object is not Envoy::Hashable, no hash will be produced.

Examples

RingHash load balancing from web to backend

Load balance requests from frontend to backend based on the HTTP header x-header:

Kubernetes
Universal
apiVersion: kuma.io/v1alpha1
kind: MeshLoadBalancingStrategy
metadata:
  name: ring-hash
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: MeshSubset
    tags:
      kuma.io/service: web
  to:
  - targetRef:
      kind: MeshService
      name: backend_kuma-demo_svc_8080
    default:
      loadBalancer:
        type: RingHash
        ringHash:
          hashPolicies:
          - type: Header
            header:
              name: x-header
type: MeshLoadBalancingStrategy
name: ring-hash
mesh: default
spec:
  targetRef:
    kind: MeshSubset
    tags:
      kuma.io/service: web
  to:
  - targetRef:
      kind: MeshService
      name: backend
    default:
      loadBalancer:
        type: RingHash
        ringHash:
          hashPolicies:
          - type: Header
            header:
              name: x-header

Disable locality-aware load balancing for backend

Requests to backend will be spread evenly across all zones where backend is deployed.

Kubernetes
Universal
apiVersion: kuma.io/v1alpha1
kind: MeshLoadBalancingStrategy
metadata:
  name: disable-la-to-backend
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend_kuma-demo_svc_8080
    default:
      localityAwareness:
        disabled: true
type: MeshLoadBalancingStrategy
name: disable-la-to-backend
mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend
    default:
      localityAwareness:
        disabled: true

Disable cross zone traffic and prioritize traffic the dataplanes on the same node and availability zone

In this example, whenever a user sends a request to the backend service, 90% of the requests will arrive at the instance with the same value of the k8s.io/node tag, 9% of the requests will go to the instance with the same value as the caller of the k8s.io/az tag, and 1% will go to the rest of the instances.

Kubernetes
Universal
apiVersion: kuma.io/v1alpha1
kind: MeshLoadBalancingStrategy
metadata:
  name: local-zone-affinity-backend
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend_kuma-demo_svc_8080
    default:
      localityAwareness:
        localZone:
          affinityTags:
          - key: k8s.io/node
          - key: k8s.io/az
type: MeshLoadBalancingStrategy
name: local-zone-affinity-backend
mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend
    default:
      localityAwareness:
        localZone:
          affinityTags:
          - key: k8s.io/node
          - key: k8s.io/az

Disable cross zone traffic and route to the local zone instances equally

In this example, when a user sends a request to the backend service, the request is routed equally to all instances in the local zone. If there are no instances in the local zone, the request will fail because there is no cross zone traffic.

Kubernetes
Universal
apiVersion: kuma.io/v1alpha1
kind: MeshLoadBalancingStrategy
metadata:
  name: local-zone-affinity-backend
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend_kuma-demo_svc_8080
    default:
      localityAwareness:
        localZone:
          affinityTags: []
type: MeshLoadBalancingStrategy
name: local-zone-affinity-backend
mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend
    default:
      localityAwareness:
        localZone:
          affinityTags: []

or

Kubernetes
Universal
apiVersion: kuma.io/v1alpha1
kind: MeshLoadBalancingStrategy
metadata:
  name: local-zone-affinity-backend
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend_kuma-demo_svc_8080
    default:
      localityAwareness:
        localZone: {}
type: MeshLoadBalancingStrategy
name: local-zone-affinity-backend
mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend
    default:
      localityAwareness:
        localZone: {}

Route within the local zone equally, but specify cross zone order

Requests to the backend service will be evenly distributed among all endpoints within the local zone. If there are fewer than 25% healthy hosts in the local zone, traffic will be redirected to other zones. Initially, traffic will be sent to the us-1 zone. In the event that the us-1 zone becomes unavailable, traffic will then be directed to all zones, except for us-2 and us-3. If these zones are also found to have unhealthy hosts, the traffic will be rerouted to us-2 and us-3.

Kubernetes
Universal
apiVersion: kuma.io/v1alpha1
kind: MeshLoadBalancingStrategy
metadata:
  name: cross-zone-backend
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend_kuma-demo_svc_8080
    default:
      localityAwareness:
        crossZone:
          failover:
          - to:
              type: Only
              zones:
              - us-1
          - to:
              type: AnyExcept
              zones:
              - us-2
              - us-3
          - to:
              type: Any
          failoverThreshold:
            percentage: 25
type: MeshLoadBalancingStrategy
name: cross-zone-backend
mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend
    default:
      localityAwareness:
        crossZone:
          failover:
          - to:
              type: Only
              zones:
              - us-1
          - to:
              type: AnyExcept
              zones:
              - us-2
              - us-3
          - to:
              type: Any
          failoverThreshold:
            percentage: 25

Prioritize traffic to data planes within the same data center and fallback cross zone in specific order

Requests to backend will be distributed based on weights, with 99.9% of requests routed to data planes in the same data center, 0.099% to data planes in the same region, and the remainder to other local instances.

When no healthy backends are available within the local zone, traffic from data planes in zones us-1, us-2, and us-3 will only fall back to zones us-1, us-2, and us-3, while in zones eu-1, eu-2, and eu-3 will only fall back to zones eu-1, eu-2, and eu-3. If there are no healthy instances in all zones eu-[1-3] or us-[1-3], requests from any instance will then fall back to us-4. If there are no healthy instances in us-4, the request will fail, as the last rule, by default, has a type of None, meaning no fallback is allowed.

Kubernetes
Universal
apiVersion: kuma.io/v1alpha1
kind: MeshLoadBalancingStrategy
metadata:
  name: local-zone-affinity-cross-backend
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend_kuma-demo_svc_8080
    default:
      localityAwareness:
        localZone:
          affinityTags:
          - key: kubernetes.io/hostname
            weight: 9000
          - key: topology.kubernetes.io/zone
            weight: 9
        crossZone:
          failover:
          - from:
              zones:
              - us-1
              - us-2
              - us-3
            to:
              type: Only
              zones:
              - us-1
              - us-2
              - us-3
          - from:
              zones:
              - eu-1
              - eu-2
              - eu-3
            to:
              type: Only
              zones:
              - eu-1
              - eu-2
              - eu-3
          - to:
              type: Only
              zones:
              - us-4
type: MeshLoadBalancingStrategy
name: local-zone-affinity-cross-backend
mesh: default
spec:
  targetRef:
    kind: Mesh
  to:
  - targetRef:
      kind: MeshService
      name: backend
    default:
      localityAwareness:
        localZone:
          affinityTags:
          - key: kubernetes.io/hostname
            weight: 9000
          - key: topology.kubernetes.io/zone
            weight: 9
        crossZone:
          failover:
          - from:
              zones:
              - us-1
              - us-2
              - us-3
            to:
              type: Only
              zones:
              - us-1
              - us-2
              - us-3
          - from:
              zones:
              - eu-1
              - eu-2
              - eu-3
            to:
              type: Only
              zones:
              - eu-1
              - eu-2
              - eu-3
          - to:
              type: Only
              zones:
              - us-4

Load balancing HTTP traffic through zone proxies

If you proxy HTTP traffic through zone proxies (zone ingress/egress), you may notice that the traffic does not reach every instance of the destination service. In the case of in-zone traffic (without zone proxies on a request path), the client is aware of all server endpoints, so if you have 10 server endpoints the traffic goes to all of them. In the case of cross-zone traffic, the client is only aware of zone ingress endpoints, so if you have 10 server endpoints and 1 zone ingress, the client only sees one zone ingress endpoint. Because zone ingress is just a TCP passthrough proxy (it does not terminate TLS), it only load balances TCP connections over server endpoints.

HTTP traffic between Envoys is upgraded to HTTP/2 automatically for performance benefits. The client’s Envoy leverages HTTP/2 multiplexing therefore it opens only a few TCP connections.

You can mitigate this problem by adjusting max_requests_per_connection setting on Envoy Cluster. For example

Kubernetes
Universal
apiVersion: kuma.io/v1alpha1
kind: MeshProxyPatch
metadata:
  name: max-requests-per-conn
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: default
spec:
  targetRef:
    kind: Mesh
  default:
    appendModifications:
    - cluster:
        operation: Patch
        match:
          name: demo-app_kuma-demo_svc_5000
          origin: outbound
        value: 'max_requests_per_connection: 1

          '
type: MeshProxyPatch
name: max-requests-per-conn
mesh: default
spec:
  targetRef:
    kind: Mesh
  default:
    appendModifications:
    - cluster:
        operation: Patch
        match:
          name: demo-app_kuma-demo_svc_5000
          origin: outbound
        value: 'max_requests_per_connection: 1

          '

This way, we allow only one in-flight request on a TCP connection. Consequently, the client will open more TCP connections, leading to fairer load balancing. The downside is that we now have to establish and maintain more TCP connections. Keep this in mind as you adjust the value to suit your needs.

All policy options

Spec is the specification of the Kuma MeshLoadBalancingStrategy resource.

Type: object

Properties

  • targetRef required

    • TargetRef is a reference to the resource the policy takes an effect on.The resource could be either a real store object or virtual resourcedefined inplace.
    • Type: object
    • Properties
      • kind
        • Kind of the referenced resource
        • Type: string
        • The value is restricted to the following:
          1. "Mesh"
          2. "MeshSubset"
          3. "MeshGateway"
          4. "MeshService"
          5. "MeshServiceSubset"
          6. "MeshHTTPRoute"
      • mesh
        • Mesh is reserved for future use to identify cross mesh resources.
        • Type: string
      • name
        • Name of the referenced resource. Can only be used with kinds: MeshService,MeshServiceSubset and MeshGatewayRoute
        • Type: string
      • tags
        • Tags used to select a subset of proxies by tags. Can only be used with kindsMeshSubset and MeshServiceSubset
        • Type: object
        • This schema accepts additional properties.
        • Properties
  • to

    • To list makes a match between the consumed services and corresponding configurations

    • Type: array

      • Items

      • Type: object

      • Properties

        • default

          • Default is a configuration specific to the group of destinations referenced in'targetRef'

          • Type: object

          • Properties

            • loadBalancer

              • LoadBalancer allows to specify load balancing algorithm.

              • Type: object

              • Properties

                • leastRequest

                  • LeastRequest selects N random available hosts as specified in 'choiceCount' (2 by default)and picks the host which has the fewest active requests
                  • Type: object
                  • Properties
                    • choiceCount
                      • ChoiceCount is the number of random healthy hosts from which the host withthe fewest active requests will be chosen. Defaults to 2 so that Envoy performstwo-choice selection if the field is not set.
                      • Type: integer
                      • Range: ≥ 2
                • maglev

                  • Maglev implements consistent hashing to upstream hosts. Maglev can be used asa drop in replacement for the ring hash load balancer any place in whichconsistent hashing is desired.

                  • Type: object

                  • Properties

                    • hashPolicies

                      • HashPolicies specify a list of request/connection properties that are used to calculate a hash.These hash policies are executed in the specified order. If a hash policy has the “terminal” attributeset to true, and there is already a hash generated, the hash is returned immediately,ignoring the rest of the hash policy list.

                      • Type: array

                        • Items

                        • Type: object

                        • Properties

                          • connection

                            • Type: object
                            • Properties
                              • sourceIP
                                • Hash on source IP address.
                                • Type: boolean
                          • cookie

                            • Type: object

                            • Properties

                              • name required

                                • The name of the cookie that will be used to obtain the hash key.
                                • Type: string
                                • Length: ≥ 1
                              • path

                                • The name of the path for the cookie.
                                • Type: string
                              • ttl

                                • If specified, a cookie with the TTL will be generated if the cookie is not present.
                                • Type: string
                          • filterState

                            • Type: object
                            • Properties
                              • key required
                                • The name of the Object in the per-request filterState, which isan Envoy::Hashable object. If there is no data associated with the key,or the stored object is not Envoy::Hashable, no hash will be produced.
                                • Type: string
                                • Length: ≥ 1
                          • header

                            • Type: object
                            • Properties
                              • name required
                                • The name of the request header that will be used to obtain the hash key.
                                • Type: string
                                • Length: ≥ 1
                          • queryParameter

                            • Type: object
                            • Properties
                              • name required
                                • The name of the URL query parameter that will be used to obtain the hash key.If the parameter is not present, no hash will be produced. Query parameter namesare case-sensitive.
                                • Type: string
                                • Length: ≥ 1
                          • terminal

                            • Terminal is a flag that short-circuits the hash computing. This field providesa ‘fallback’ style of configuration: “if a terminal policy doesn’t work, fallbackto rest of the policy list”, it saves time when the terminal policy works.If true, and there is already a hash computed, ignore rest of the list of hash polices.
                            • Type: boolean
                          • type required

                            • Type: string
                            • The value is restricted to the following:
                              1. "Header"
                              2. "Cookie"
                              3. "SourceIP"
                              4. "QueryParameter"
                              5. "FilterState"
                    • tableSize

                      • The table size for Maglev hashing. Maglev aims for “minimal disruption”rather than an absolute guarantee. Minimal disruption means that whenthe set of upstream hosts change, a connection will likely be sentto the same upstream as it was before. Increasing the table size reducesthe amount of disruption. The table size must be prime number limited to 5000011.If it is not specified, the default is 65537.
                      • Type: integer
                      • Range: between 1 and 5000011
                • random

                  • Random selects a random available host. The random load balancer generallyperforms better than round-robin if no health checking policy is configured.Random selection avoids bias towards the host in the set that comes after a failed host.
                  • Type: object
                  • Properties
                • ringHash

                  • RingHash implements consistent hashing to upstream hosts. Each host is mappedonto a circle (the “ring”) by hashing its address; each request is then routedto a host by hashing some property of the request, and finding the nearestcorresponding host clockwise around the ring.

                  • Type: object

                  • Properties

                    • hashFunction

                      • HashFunction is a function used to hash hosts onto the ketama ring.The value defaults to XXHASH. Available values – XXHASH, MURMURHASH2.
                      • Type: string
                      • The value is restricted to the following:
                        1. "XXHash"
                        2. "MurmurHash2"
                    • hashPolicies

                      • HashPolicies specify a list of request/connection properties that are used to calculate a hash.These hash policies are executed in the specified order. If a hash policy has the “terminal” attributeset to true, and there is already a hash generated, the hash is returned immediately,ignoring the rest of the hash policy list.

                      • Type: array

                        • Items

                        • Type: object

                        • Properties

                          • connection

                            • Type: object
                            • Properties
                              • sourceIP
                                • Hash on source IP address.
                                • Type: boolean
                          • cookie

                            • Type: object

                            • Properties

                              • name required

                                • The name of the cookie that will be used to obtain the hash key.
                                • Type: string
                                • Length: ≥ 1
                              • path

                                • The name of the path for the cookie.
                                • Type: string
                              • ttl

                                • If specified, a cookie with the TTL will be generated if the cookie is not present.
                                • Type: string
                          • filterState

                            • Type: object
                            • Properties
                              • key required
                                • The name of the Object in the per-request filterState, which isan Envoy::Hashable object. If there is no data associated with the key,or the stored object is not Envoy::Hashable, no hash will be produced.
                                • Type: string
                                • Length: ≥ 1
                          • header

                            • Type: object
                            • Properties
                              • name required
                                • The name of the request header that will be used to obtain the hash key.
                                • Type: string
                                • Length: ≥ 1
                          • queryParameter

                            • Type: object
                            • Properties
                              • name required
                                • The name of the URL query parameter that will be used to obtain the hash key.If the parameter is not present, no hash will be produced. Query parameter namesare case-sensitive.
                                • Type: string
                                • Length: ≥ 1
                          • terminal

                            • Terminal is a flag that short-circuits the hash computing. This field providesa ‘fallback’ style of configuration: “if a terminal policy doesn’t work, fallbackto rest of the policy list”, it saves time when the terminal policy works.If true, and there is already a hash computed, ignore rest of the list of hash polices.
                            • Type: boolean
                          • type required

                            • Type: string
                            • The value is restricted to the following:
                              1. "Header"
                              2. "Cookie"
                              3. "SourceIP"
                              4. "QueryParameter"
                              5. "FilterState"
                    • maxRingSize

                      • Maximum hash ring size. Defaults to 8M entries, and limited to 8M entries,but can be lowered to further constrain resource use.
                      • Type: integer
                      • Range: between 1 and 8000000
                    • minRingSize

                      • Minimum hash ring size. The larger the ring is (that is,the more hashes there are for each provided host) the better the request distributionwill reflect the desired weights. Defaults to 1024 entries, and limited to 8M entries.
                      • Type: integer
                      • Range: between 1 and 8000000
                • roundRobin

                  • RoundRobin is a load balancing algorithm that distributes requestsacross available upstream hosts in round-robin order.
                  • Type: object
                  • Properties
                • type required

                  • Type: string
                  • The value is restricted to the following:
                    1. "RoundRobin"
                    2. "LeastRequest"
                    3. "RingHash"
                    4. "Random"
                    5. "Maglev"
            • localityAwareness

              • LocalityAwareness contains configuration for locality aware load balancing.
              • Type: object
              • Properties
                • crossZone
                  • CrossZone defines locality aware load balancing priorities when dataplane proxies inside local zoneare unavailable
                  • Type: object
                  • Properties
                    • failover
                      • Failover defines list of load balancing rules in order of priority
                      • Type: array
                        • Items
                        • Type: object
                        • Properties
                          • from
                            • From defines the list of zones to which the rule applies
                            • Type: object
                            • Properties
                              • zones required
                                • Type: array
                                  • Items
                                  • Type: string
                          • to required
                            • To defines to which zones the traffic should be load balanced
                            • Type: object
                            • Properties
                              • type required
                                • Type defines how target zones will be picked from available zones
                                • Type: string
                                • The value is restricted to the following:
                                  1. "None"
                                  2. "Only"
                                  3. "Any"
                                  4. "AnyExcept"
                              • zones
                                • Type: array
                                  • Items
                                  • Type: string
                    • failoverThreshold
                      • FailoverThreshold defines the percentage of live destination dataplane proxies below which load balancing to thenext priority starts.Example: If you configure failoverThreshold to 70, and you have deployed 10 destination dataplane proxies.Load balancing to next priority will start when number of live destination dataplane proxies drops below 7.Default 50
                      • Type: object
                      • Properties
                        • percentage required
                • disabled
                  • Disabled allows to disable locality-aware load balancing.When disabled requests are distributed across all endpoints regardless of locality.
                  • Type: boolean
                • localZone
                  • LocalZone defines locality aware load balancing priorities between dataplane proxies inside a zone
                  • Type: object
                  • Properties
                    • affinityTags
                      • AffinityTags list of tags for local zone load balancing.
                      • Type: array
                        • Items
                        • Type: object
                        • Properties
                          • key required
                            • Key defines tag for which affinity is configured
                            • Type: string
                          • weight
                            • Weight of the tag used for load balancing. The bigger the weight the bigger the priority.Percentage of local traffic load balanced to tag is computed by dividing weight by sum of weights from all tags.For example with two affinity tags first with weight 80 and second with weight 20,then 80% of traffic will be redirected to the first tag, and 20% of traffic will be redirected to second one.Setting weights is not mandatory. When weights are not set control plane will compute default weight based on list order.Default: If you do not specify weight we will adjust them so that 90% traffic goes to first tag, 9% to next, and 1% to third and so on.
                            • Type: integer
        • targetRef required

          • TargetRef is a reference to the resource that represents a group ofdestinations.
          • Type: object
          • Properties
            • kind
              • Kind of the referenced resource
              • Type: string
              • The value is restricted to the following:
                1. "Mesh"
                2. "MeshSubset"
                3. "MeshGateway"
                4. "MeshService"
                5. "MeshServiceSubset"
                6. "MeshHTTPRoute"
            • mesh
              • Mesh is reserved for future use to identify cross mesh resources.
              • Type: string
            • name
              • Name of the referenced resource. Can only be used with kinds: MeshService,MeshServiceSubset and MeshGatewayRoute
              • Type: string
            • tags
              • Tags used to select a subset of proxies by tags. Can only be used with kindsMeshSubset and MeshServiceSubset
              • Type: object
              • This schema accepts additional properties.
              • Properties

Generated with json-schema-md-doc Thu May 08 2025 16:29:13 GMT+0000 (Coordinated Universal Time)

Thank you for your feedback.
Was this page useful?
Too much on your plate? close cta icon
More features, less infrastructure with Kong Konnect. 1M requests per month for free.
Try it for Free
  • Kong
    Powering the API world

    Increase developer productivity, security, and performance at scale with the unified platform for API management, service mesh, and ingress controller.

    • Products
      • Kong Konnect
      • Kong Gateway Enterprise
      • Kong Gateway
      • Kong Mesh
      • Kong Ingress Controller
      • Kong Insomnia
      • Product Updates
      • Get Started
    • Documentation
      • Kong Konnect Docs
      • Kong Gateway Docs
      • Kong Mesh Docs
      • Kong Insomnia Docs
      • Kong Konnect Plugin Hub
    • Open Source
      • Kong Gateway
      • Kuma
      • Insomnia
      • Kong Community
    • Company
      • About Kong
      • Customers
      • Careers
      • Press
      • Events
      • Contact
  • Terms• Privacy• Trust and Compliance
© Kong Inc. 2025