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 Sleep pod in region1 zone1 as the source of requests to the HelloWorld service. You will configure Istio with the following distribution across localities:

RegionZone% of traffic
region1zone170
region1zone220
region2zone30
region3zone410

Configure Weighted Distribution

Apply a DestinationRule that configures the following:

  • Outlier detection for the HelloWorld service. 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 HelloWorld service as described in the table above.

  1. $ kubectl --context="${CTX_PRIMARY}" apply -n sample -f - <<EOF
  2. apiVersion: networking.istio.io/v1beta1
  3. kind: DestinationRule
  4. metadata:
  5. name: helloworld
  6. spec:
  7. host: helloworld.sample.svc.cluster.local
  8. trafficPolicy:
  9. loadBalancer:
  10. localityLbSetting:
  11. enabled: true
  12. distribute:
  13. - from: region1/zone1/*
  14. to:
  15. "region1/zone1/*": 70
  16. "region1/zone2/*": 20
  17. "region3/zone4/*": 10
  18. outlierDetection:
  19. consecutive5xxErrors: 100
  20. interval: 1s
  21. baseEjectionTime: 1m
  22. EOF

Verify the distribution

Call the HelloWorld service from the Sleep pod:

  1. $ kubectl exec --context="${CTX_R1_Z1}" -n sample -c sleep \
  2. "$(kubectl get pod --context="${CTX_R1_Z1}" -n sample -l \
  3. app=sleep -o jsonpath='{.items[0].metadata.name}')" \
  4. -- curl -sSL helloworld.sample:5000/hello

Repeat 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.

See also

Before you begin

Initial steps before configuring locality load balancing.

Locality failover

This task demonstrates how to configure your mesh for locality failover.

Before you begin

Initial steps before installing Istio on multiple clusters.

Cleanup

Cleanup steps for locality load balancing.

Install Multi-Primary

Install an Istio mesh across multiple primary clusters.

Install Multi-Primary on different networks

Install an Istio mesh across multiple primary clusters on different networks.