天天看點

Istio - TrafficManagement - Mirror

> HTTP流量鏡像指的是将流量轉發到原目标服務的同時将流量給另外一個目标服務,請求正常的關注原始服務,而等待不用鏡像的流量傳回。

#### 什麼場景需要用的流量鏡像

例如上線了新的版本,但對于可靠性不是很有信心,可以将請求的流量将傳入目前使用的版本鏡像到新的版本來測試,對目前使用的版本不會産生影響,同時也可以測試到新版本的性能等方面。

#### 通過例子來了解

目前是使用的v1版本的api,由于業務需求新增v2版本的api,但v2沒有經過完整的測試,SRE團隊對于上線後不是很有信心去確定可靠性。是以采取了流量鏡像針對v1版本的流量鏡像到v2版本來進行可靠性驗證。

Istio - TrafficManagement - Mirror

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-v1-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
      version: 1
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: nginx
        version: 1
    spec:
      containers:
        - image: 'nginx:latest'
          name: nginx-deployment
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-v2-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
      version: 2
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: nginx
        version: 2
    spec:
      containers:
        - image: 'nginx:latest'
          name: nginx-deployment
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: ClusterIP
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: nginx-dr
spec:
  host: nginx-service
  subsets:
  - name: v1
    labels:
      version: 1
  - name: v2
    labels:
      version: 2
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata: 
  name: nginx-vs
spec:
  hosts:
  - "*"
  http:
  - route: 
    - destination:
        host: nginx-service
        subset: v1
    mirror:
        host: nginx-service
        subset: v2      

繼續閱讀