Pages - Menu

2021年9月8日 星期三

[istio]istio virtualService delegate使用

前言

這次起因應該是自己亂搞吧,會用到delegate的原因,是為了要解決在維護時上的痛點。
因目前使用flagger canary,
導致每個服務就一個virtualService (下面會用VS代替),
而多個服務會共用一個host ,導致在維護上的困難。
而且在kiali上面會出現警告(fig.1),看了實在礙眼。


(fig.1)

正文


所以使用delegate。這樣的話,流量會先導到 delegate vs,之後才會根據path到各服務的vs。

delegate 有幾點要注意,

  1. 不支援 regex
  2. 在delegate上寫rewrite不會被轉導,要在導過去的vs寫。
  3. 目前測試只能在同一個namespace上面。如果不是用藍綠佈署自定義的話,在destination 上面,可以使用完整的FQDN,是可以執行的。(例如: video-admin-primary.default.svc.cluster.local)
  4. 由於是使用* 萬用字元,所以mesh也不能用了,如果是用domain呼叫叢集內的服務的話,要注意

VS delegate

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: control-dashboard
  namespace: default
spec:
  hosts:
  - "*"
  gateways:
    - istio-gateway-external.istio-system.svc.cluster.local
  http:
    - delegate:
        name: video-admin
        namespace: default
      match:
        - uri:
            prefix: /ezio
        - uri:
            prefix: /abc
        - uri:
            prefix: /api
      name: reviews-v2-routes
    - delegate:
        name: tw-frontend
        namespace: default
      match:
        - uri:
            prefix: /
      name: tw-frontend

服務的 vs,(注意:此處的yaml是由flagger自動產生的)

kind: VirtualService
apiVersion: networking.istio.io/v1alpha3
metadata:
  name: video-admin
  namespace: default
spec:
  hosts: []
  http:
    - match:
        - uri:
            prefix: /api
        - uri:
            prefix: /abc
        - uri:
            prefix: /ezio
      rewrite:
        uri: /api
      route:
        - destination:
            host: video-admin-primary
          weight: 100
        - destination:
            host: video-admin-canary
          weight: 0

ps. 使用canary的話,在service下面加上

delegation: true  

ref. How does Flagger interact with Istio?

apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
  name: example-api-qa-v2
  namespace: istio-example
spec:
  provider: istio
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: example-api-qa-v2
  autoscalerRef:
    apiVersion: autoscaling/v1
    kind: HorizontalPodAutoscaler
    name: example-api-qa-v2

  service:
    delegation: true    # use delegate
    name: example-api-qa-v2
    port: 80
    targetPort: 80
    portName: http
    portDiscovery: true

    trafficPolicy:
      tls:
        mode: DISABLE
    match:
      - uri:
          prefix: /api-v2
    rewrite:
      uri: /api
    timeout: 30s
  analysis:
    # analysis spend time  : interval * iterations 
    # 時間間隔 (默認 60s)
    interval: 30s
    # 回滾前的最大失敗指標檢查次數(可能因為檢查時間差的關係,至少會有兩次失敗)
    threshold: 5
    iterations: 1
    metrics:
      - name: request-success-rate
        thresholdRange:
          min: 99
        interval: 1m
      - name: request-duration
        thresholdRange:
          max: 500
        interval: 30s
    webhooks:
      - name: load-test-get
        type: pre-rollout
        url: http://flagger-loadtester.tools/
        timeout: 15s
        metadata:
          type: cmd
          cmd: "hey -z 1m -q 10 -c 2 http://example-api-qa-v2-canary.istio-example"
      - name: "notify"
        type: event
        url: http://webhook-api.tools/webhook/flagger
        timeout: 5s
        metadata:
          channel: "-1001429024676"
      - name: load-test
        type: rollout
        url: http://flagger-loadtester.tools/
        timeout: 5s
        metadata:
          type: cmd
          cmd: "hey -z 1m -q 10  http://example-api-qa-v2-canary.istio-example"

ref.
VS Delegate
VS HTTPMatchRequest

沒有留言:

張貼留言