istio实现流量控制金丝雀部署

介绍

主要讲解istio的流量控制实现原理 github上test-walle的项目打成了demo:1.0和2.0的版本

用到的yaml文件:https://github.com/ciweigg2/kubernetes-yaml/tree/master/istio-canary

部署Service

vi test-walle-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: test-walle
  labels:
    app: test-walle
    service: test-walle
spec:
  ports:
  - port: 8081
    name: http
  selector:
    app: test-walle
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: walle-account

部署V1版本的服务

vi test-walle-deploymentV1.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-walle-v1
  labels:
    app: test-walle
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-walle
      version: v1
  template:
    metadata:
      labels:
        app: test-walle
        version: v1
    spec:
      serviceAccountName: walle-account
      containers:
      - name: test-walle
        image: demo:1.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8081

部署V2版本的服务

vi test-walle-deploymentV2.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-walle-v2
  labels:
    app: test-walle
    version: v2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-walle
      version: v2
  template:
    metadata:
      labels:
        app: test-walle
        version: v2
    spec:
      serviceAccountName: walle-account
      containers:
      - name: test-walle
        image: demo:2.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8081

部署gateway

vi test-walle-gateway.yaml

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: qingfeng-deve
spec:
  selector:
    istio: ingressgateway # 使用 istio 默认的 ingress gateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"

部署DestinationRule

控制路由版本的呀

vi test-walle-destinationrule.yaml

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: test-walle
spec:
  host: test-walle
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

部署VirtualService

都是50测试流量呀 配置test.ciwei.com hosts解析

vi test-walle-virtualservice.yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: walle
  namespace: default
spec:
  gateways:
  - qingfeng-deve
  hosts:
  - test.ciwei.com
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: test-walle
        subset: v1
      weight: 50
    - destination:
        host: test-walle
        subset: v2
      weight: 50

访问:test.ciwei.com 发现流量55开啦

部署全部yaml测试

部署

kubectl apply -f .

修改VirtualService

控制v1流量10% v2流量90% 测试一下呀

vi test-walle-virtualservice.yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: walle
  namespace: default
spec:
  gateways:
  - qingfeng-deve
  hosts:
  - test.ciwei.com
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: test-walle
        subset: v1
      weight: 10
    - destination:
        host: test-walle
        subset: v2
      weight: 90

访问:test.ciwei.com

发现大部分流量都集中在v2版本

监控

前面文章讲过istio开启grafana暴露端口的 然后在界面查看demo2个版本的流量情况下 上面有200的请求和500的请求可以监控是否可以正常完成金丝雀部署


文章作者: Ciwei
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Ciwei !
 上一篇
flagger集成istio自动完成金丝雀部署 flagger集成istio自动完成金丝雀部署
介绍flagger根据prometheus的指标自动发布金丝雀版本 流量会根据访问请求的稳定性慢慢把权重放到新的版本上(金丝雀版本) 完成金丝雀部署全部是自动化的 可以在grafana查看监控呀 参考:https://docs.flagge
2019-06-30
下一篇 
linux中的vi命令 linux中的vi命令
一直觉得vi命令不好用介绍一下工作中常用的 G 移至行行首 nG 移至第n行行首 n+ 移n行行首 n- 移n行行首 n$ 移n行(1表示本行)行尾 0 所行行首 $ 所行行尾 ^ 所行首字母 h,j,k,l 左移移移右移 H 前屏幕首行行
2019-06-30
  目录