8

istio学习笔记(4)-基于istio做灰度发布

 3 years ago
source link: http://vearne.cc/archives/39418
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
版权声明 本站原创文章 由 萌叔 发表
转载请注明 萌叔 | http://vearne.cc

警告:本文仅用于萌叔自己总结之用,对其它人而言可能毫无营养,没有阅读价值。

可以使用istio可以做灰度发布,下面简单记录一下步骤

2. 原理&配置

envoy

基于istio做灰度发布需要用到envoy的负载均衡功能。
回想一下我们再nginx中是如何配置负载均衡的

    upstream backend { 
        server 192.168.101.10:8080 weight=1; 
        server 192.168.101.12:8080 weight=2;
    }

2.1 配置

可用通过配置权重来控制流向上游服务的流量
类似的,在istio中需要用到VirtualService

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: vs-backend
  namespace: test
spec:
  gateways:
    - gateway-backend-gateway-io.istio-system.svc.cluster.local
  hosts:
    - backend.gateway.io
  http:
    - retries: {}
      route:
        - destination:
            host: sv-backend.test.svc.cluster.local
            subset: v0-0-1
          weight: 20
        - destination:
            host: sv-backend.test.svc.cluster.local
            subset: v0-0-2
          weight: 80
      timeout: 3s

The proportion of traffic to be forwarded to the service version. (0-100). Sum of weights across destinations SHOULD BE == 100.If there is only one destination in a rule, the weight value is assumed to be 100.

后端各个版本的权重和应该等于100

这里需要注意的是subset, subset其实是istio中的一种资源类型。它的命名需要满足正则表达式

[a-z0-9]([-a-z0-9]*[a-z0-9])?

subset定义在DestinationRule

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: dr-backend
  namespace: test
spec:
  host: sv-backend.test.svc.cluster.local
  subsets:
    - labels:
        version: v0.0.1
      name: v0-0-1
      trafficPolicy:
        loadBalancer:
          simple: ROUND_ROBIN
    - labels:
        version: v0.0.2
      name: v0-0-2
      trafficPolicy:
        loadBalancer:
          simple: ROUND_ROBIN

2.2 流程

envoy启动之后,会与pilot进行通讯获取配置信息,当服务frontend调用backend的时候,流量会被劫持,按照负载均衡配置的权重进行转发,灰度就实现了。
注意 对于单体应用,如果也想对多个版本进行灰度,需要使用istio-ingressgateway,它的作用于nginx类同,实现是envoy


请我喝杯咖啡

微信支付码


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK