Istio 11 根据来源进行路由

Submitted by Lizhe on Tue, 06/23/2020 - 06:33

金丝雀的用例里,是基于 HTTP Header 进行路由的,这里尝试基于 源Pod ( sleep ) 的 label 对请求进行路由

首先我们去修改 sleep 应用,把它拆分成两个部署,分别label成 v1 和 v2

apiVersion: v1

kind: Service

metadata:

  name: sleep

  namespace: lizhe 

  labels: 

    app: sleep

spec: 

  selector: 

    app: sleep

  ports: 

    - name: ssh

      port: 80

 

---

 

apiVersion: apps/v1

kind: Deployment

metadata:

  name: sleep-v1

  namespace: lizhe

spec: 

  replicas: 1

  selector:

    matchLabels:

      app: sleep

      version: v1

  template:

    metadata:

      labels:

        app: sleep

        version: v1

    spec: 

      containers:

      - name: flaskapp

        image: dustise/sleep

        imagePullPolicy: IfNotPresent

 

---

 

apiVersion: apps/v1

kind: Deployment

metadata:

  name: sleep-v2

  namespace: lizhe

spec: 

  replicas: 1

  selector:

    matchLabels:

      app: sleep

      version: v2

  template:

    metadata:

      labels:

        app: sleep

        version: v2

    spec: 

      containers:

      - name: flaskapp

        image: dustise/sleep

        imagePullPolicy: IfNotPresent

 

 

20200623025459

20200623032027

 

20200623032036

 

20200623032324

 

apiVersion: networking.istio.io/v1alpha3

kind: VirtualService

metadata:

  name: flaskapp-canary

  namespace: lizhe

spec:

  hosts:

  - flaskapp-service

  http:

  - match:

    - sourceLabels:

        version: v1

    route:

    - destination:

        host: flaskapp-service

        subset: v1

  - route:

    - destination:

        host: flaskapp-service

        subset: v2

 

上面的配置会将 来自于 label version v1 的请求指向 app v1

将 来自于 label version v2 的请求指向 app v2

 

在 v1 上

20200623033521

 

在 v2 上

20200623033552

 

kiali 上是这样的

20200623033532

20200623033657