本文使用istio版本:1.4.2
上章內容只是簡單運行了Bookinfo示例(Istio使用【Bookinfo示例】),訪問頁面,Reviews雖然有三個版本,但是刷新瀏覽器,三個版本是隨機返回。本章內容仍然使用官方樣例配置,定義一些自定義路由規則。在這之前最好了解下Istio使用【CRDs】。
創建所有服務的DestinationRule
kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
定義V1和V2版本8:2比重,V3不返回
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v1
weight: 80
- destination:
host: reviews
subset: v2
weight: 20
定義如果Header中包含jason用戶返回V2版本,否則返回V3版本
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- match:
- headers:
end-user:
exact: jason
route:
- destination:
host: reviews
subset: v2
- route:
- destination:
host: reviews
subset: v3
其它可以參考samples/bookinfo/networking/目錄下配置。