灰度发布:多版本并存,流量按权重分配

k8s 灰度发布_灰度

k8s 灰度发布_路由配置_02

k8s 灰度发布_路由配置_03

# 这个 VirtualService 列表包含 4 个服务:details、productpage、ratings 和 reviews 
# 的路由配置。reviews 服务的配置被更新了两次。

apiVersion: v1  
items:  

# details 服务的路由规则,100% 流量定向到子集 v1
- apiVersion: networking.istio.io/v1beta1  
  kind: VirtualService
  metadata:  
    name: details 
    namespace: demo-project
  spec:
    hosts:  
    - details  
    http:
    - match:  
      - port: 9080   
      route:
      - destination:  
          host: details  
          subset: v1   
        weight: 100   

# productpage 服务的路由规则,100% 流量定向到子集 v1 
- apiVersion: networking.istio.io/v1beta1  
  kind: VirtualService
  metadata:  
    name: productpage 
    namespace: demo-project
  spec:  
    hosts:  
    - productpage
    http:
    - match:  
      - port: 9080   
      route:
      - destination:  
          host: productpage  
          subset: v1
        weight: 100  

# ratings 服务的路由规则,100% 流量定向到子集 v1
- apiVersion: networking.istio.io/v1beta1  
  kind: VirtualService
  metadata:  
    name: ratings  
    namespace: demo-project 
  spec:
    hosts:  
    - ratings
    http:
    - match:  
      - port: 9080   
      route:
      - destination:  
          host: ratings  
          subset: v1   
        weight: 100  

# reviews 服务的路由规则,流量按 44% 定向到子集 v2,56% 定向到子集 v3    
- apiVersion: networking.istio.io/v1beta1  
  kind: VirtualService
  metadata:  
    name: reviews  
    namespace: demo-project
  spec:
    hosts:  
    - reviews
    http:
    - match:  
      - port: 9080  
      route:
      - destination:  
          host: reviews  
          subset: v2
        weight: 28   
      - destination:  
          host: reviews  
          subset: v3   
        weight: 72