本地加权分布
按照本指南配置跨区域的流量分布。
在继续操作之前,请确保已完成开始之前中的步骤。
在此任务中,您将使用region1
zone1
中的curl
pod作为请求HelloWorld
服务的源。您将使用以下跨区域的分布配置 Istio
区域 | 可用区 | 流量百分比 |
---|---|---|
region1 | zone1 | 70 |
region1 | zone2 | 20 |
region2 | zone3 | 0 |
region3 | zone4 | 10 |
配置加权分布
应用一个配置以下内容的DestinationRule
$ 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
EOF
验证分布
从curl
pod 调用HelloWorld
服务
$ 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/hello
重复此操作多次,并验证每个 pod 的回复数量是否与本指南顶部的表格中预期的百分比匹配。
恭喜!您已成功配置区域负载均衡!
后续步骤
清理此任务中使用的资源和文件。