Locality weighted distribution
Follow this guide to configure the distribution of traffic across localities.
Before proceeding, be sure to complete the steps under before you begin.
In this task, you will use the curl pod in region1 zone1 as the source of
requests to the HelloWorld service. You will configure Istio with the following
distribution across localities:
| Region | Zone | % of traffic |
|---|---|---|
region1 | zone1 | 70 |
region1 | zone2 | 20 |
region2 | zone3 | 0 |
region3 | zone4 | 10 |
Configure Weighted Distribution
Apply a DestinationRule that configures the following:
Outlier detection for the
HelloWorldservice. This is required in order for distribution to function properly. In particular, it configures the sidecar proxies to know when endpoints for a service are unhealthy.Weighted Distribution for the
HelloWorldservice as described in the table above.
$ kubectl --context="${CTX_PRIMARY}" apply -n sample -f - <<EOF
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
name: helloworld
spec:
host: helloworld.sample.svc.cluster.local
trafficPolicy:
loadBalancer:
localityLbSetting:
enabled: true
distribute:
- from: region1/zone1/*
to:
"region1/zone1/*": 70
"region1/zone2/*": 20
"region3/zone4/*": 10
outlierDetection:
consecutive5xxErrors: 100
interval: 1s
baseEjectionTime: 1m
EOFVerify the distribution
Call the HelloWorld service from the curl pod:
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c curl \
"$(kubectl get pod --context="${CTX_R1_Z1}" -n sample -l \
app=curl -o jsonpath='{.items[0].metadata.name}')" \
-- curl -sSL helloworld.sample:5000/helloRepeat this a number of times and verify that the number of replies for each pod match the expected percentage in the table at the top of this guide.
Congratulations! You successfully configured locality distribution!
Next steps
Cleanup resources and files from this task.