按Header分流

按照 HTTP Header 分流的一个重要好处就是可以固定某些用户在某些特定的版本上

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nginx-default-v2
  namespace: lizhe
spec: 
  hosts:
  - nginx-service
  http:
  - match:
    - headers:
        ver: 
          exact: v2
    route: 
    - destination:
        host: nginx-service
        subset: v2
  - match:
    - headers:
        ver: 
          exact: v3
    route: 
    - destination:
        host: nginx-service
        subset: v3
  - route: 
    - destination: 
        host: nginx-service
        subset: v1

上面规则的 默认会将流量导入到 v1 ,如果 request header 中指定了版本,那么会导入到指定的版本

curl http://nginx-service/helloworld.html
curl http://nginx-service/helloworld.html -H 'ver:v2'
curl http://nginx-service/helloworld.html -H 'ver:v3'

Send a Message