Traffic Route
must select the data plane proxies to route the connection between them.
Kuma also supports locality aware load balancing.
The control plane creates a default TrafficRoute
every time the new Mesh
is created. The default TrafficRoute
enables the traffic between all the services in the mesh.
type: TrafficRoute
name: route-all-default
mesh: default
sources:
- match:
kuma.io/service: '*'
destinations:
- match:
kuma.io/service: '*'
conf:
loadBalancer:
roundRobin: {}
split:
- weight: 100
destination:
By default when a service makes a request to another service, Kuma will round robin the request across every data plane proxy belogning to the destination service. It is possible to change this behavior by using this policy, for example:
apiVersion: kuma.io/v1alpha1
kind: TrafficRoute
mesh: default
metadata:
name: route-example
sources:
- match:
kuma.io/service: backend_default_svc_80
destinations:
- match:
kuma.io/service: redis_default_svc_6379
conf:
split:
- weight: 90
destination:
kuma.io/service: redis_default_svc_6379
version: '1.0'
destination:
kuma.io/service: redis_default_svc_6379
version: '2.0'
We will apply the configuration with kubectl apply -f [..]
.
We will apply the configuration with kumactl apply -f [..]
or via the .
Note that routing can be applied not just on the automatically provisioned service
Kuma tag, but on any other tag that we may want to add to our data plane proxies (like version
in the example above).
Kuma utilizes positive weights in the TrafficRoute
policy and not percentages, therefore Kuma does not check if the total adds up to 100. If we want to stop sending traffic to a destination service we change the weight
for that service to 0.
Load balancer types
There are different load balancing algorithms that can be used to determine how traffic is routed to the destinations. By default TrafficRoute
uses the roundRobin
load balancer, but more options are available:
roundRobin
is a simple algorithm in which each available upstream host is selected in round robin order.Example:
loadBalancer:
roundRobin: {}
leastRequest
uses different algorithms depending on whether the hosts have the same or different weights. It has a single configuration fieldchoiceCount
, which denotes the number of random healthy hosts from which the host with the fewer active requests will be chosen.loadBalancer:
leastRequest:
choiceCount: 8
ringHash
implements consistent hashing to the upstream hosts. It has the following fields:hashFunction
the hash function used to hash the hosts onto the ketama ring. Can beXX_HASH
orMURMUR_HASH_2
.minRingSize
minimum hash ring size.maxRingSize
maximum hash ring size.
Example:
random
selects a random available host.Example:
loadBalancer:
random: {}
maglev
implements consistent hashing to upstream hostsExample:
maglev: {}