地區加權分佈
依照本指南設定跨區域的流量分配。
在繼續之前,請務必完成開始之前下的步驟。
在此任務中,您將使用 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 的回覆次數是否與本指南頂部表格中的預期百分比相符。
恭喜! 您已成功設定區域分配!
後續步驟
清除此任務中的資源和檔案。