測試環境版本:
> istio: 1.13.1
> kubernetes: v1.23.4
本次測試使用istio提供的HelloWorld v1v2 example
HelloWorld、Sleep兩個微服務在驗證跨叢集流量時已部署,如已存在可跳過
在cluster1部署HelloWorld v1
kubectl apply --context="${CTX_CLUSTER1}" \
-f samples/helloworld/helloworld.yaml \
-l version=v1 -n sample
在cluster2部署HelloWorld v2
kubectl apply --context="${CTX_CLUSTER2}" \
-f samples/helloworld/helloworld.yaml \
-l version=v2 -n sample
部署sleep
kubectl apply --context="${CTX_CLUSTER1}" \
-f samples/sleep/sleep.yaml -n sample
kubectl apply --context="${CTX_CLUSTER2}" \
-f samples/sleep/sleep.yaml -n sample
canary.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: helloworld
spec:
hosts:
- helloworld
http:
- route:
- destination:
host: helloworld.sample.svc.cluster.local
subset: v1
weight: 80
- destination:
host: helloworld.sample.svc.cluster.local
subset: v2
weight: 20
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: helloworld
spec:
host: helloworld.sample.svc.cluster.local
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
部署金絲雀部署
kubectl apply -f canary.yaml -n sample
### 結果測試
```bash=
for i in $(seq 10); do kubectl --context=$CTX_CLUSTER1 \
-n sample exec "$(kubectl get pod --context="${CTX_CLUSTER1}" -n sample -l app=sleep -o jsonpath='{.items[0].metadata.name}')" \
-c sleep -- curl -s helloworld:5000/hello; done