当前位置:网站首页>Traffic replication in istio Service Grid

Traffic replication in istio Service Grid

2022-06-22 13:45:00 Jiangxl~

1.Istio Traffic replication in the service grid

Before releasing the new version , Test colleagues will use many test tools to pressure test the new version of the program , Although it can simulate a lot of traffic , But it is not a real traffic request , There is still no guarantee that other problems will occur after the launch .

When you need to test a new version with real online traffic , But we can't really make the version under test serve online users , Based on this situation ,Istio Can pass VirtualService Virtual services copy the real online traffic to other environments .

Istio The technology of traffic replication is called traffic mirroring , It is mainly used to copy the real online traffic , And then through Proxy The agent processes the request according to the policy , Then forward to a certain version of the program , It does not affect the real traffic request .

Istio Stream mirroring is replicated Web Request , If a user writes data in the database , This request will also be copied , So when doing traffic mirroring , It must be to copy the traffic of the online environment to the test environment for use , Even if there is a request for data submission, it will not affect online users .

Istio Application scenarios of traffic mirroring :

  • Online troubleshooting .
  • Verify the functionality of the new version of the application with real traffic .
  • Pressure test the real flow request .
  • Collect real traffic data for analysis .

Learn before Istio They all pass their own test items , We will deploy a project to Istio Test the traffic image .

General implementation steps of traffic mirroring :

  • stay Istio Several different versions of the program are deployed , To configure Service Hang these programs at the same time .
  • To configure Istio Of VirtualService resources , Distribute all online traffic to V1 The program version of provides services .
  • stay VirtualService Configure traffic mirroring in , Copy V1 The traffic of the version reaches V2 Version of the program .

2. Demonstrate traffic replication through a set of cases

2.1. stay Istio Deployment in China Nginx Multiple versions of the project

Let's create several different versions of Nginx project ,V1 Version is used in online real-world environment ,V2 Version a test version for a new feature .

1) establish Nginx Where the project is located Namespace And open Sidecar Automatic injection

1. establish namespace
[[email protected] myproject]# kubectl create ns istio-project
namespace/istio-project created

2. Turn on Sidecar Automatic injection 
[[email protected] myproject]# kubectl label ns istio-project istio-injection=enabled
namespace/istio-project labeled

2) stay Istio Deployment in China Nginx V1 edition

Nginx V1 The version is online .

1. Quickly generate a Nginx Of Deployment Resource orchestration file 
[[email protected]-master myproject]# kubectl create deployment nginx --image=nginx:1.15 --dry-run -o yaml > nginx-v1.yaml

2. Configure resource orchestration file 
[[email protected]-master myproject]# vim nginx-v1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-v1
  namespace: istio-project
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
      version: v1			# Different versions can be distinguished by labels 
  template:
    metadata:
      labels:
        app: nginx
        version: v1
    spec:
      containers:
      - image: nginx:1.15
        name: nginx-v1


3. establish V1 Version of Nginx Program 
[[email protected]-master myproject]# kubectl apply -f nginx-v1.yaml
deployment.apps/nginx-v1 created

3) Deploy in the same way Nginx V2 edition

Nginx V2 Version is a new version test phase , take V2 In the version resource orchestration file app Tag value modification , prevent V2 The test version is connected to Service Resources to provide services for online users .

1. Direct copy nginx-v1 The layout file of the version 
[[email protected]-master myproject]# cp nginx-v1.yaml nginx-v2.yaml

2. take nginx-v1 Change the label to nginx-v2
[[email protected]-master myproject]# vim nginx-v2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-v2
  namespace: istio-project
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
      version: v2
  template:
    metadata:
      labels:
        app: nginx
        version: v2
    spec:
      containers:
      - image: nginx:1.15
        name: nginx-v2

3. establish V2 Version of the program 
[[email protected]-master myproject]# kubectl apply -f nginx-v2.yaml
deployment.apps/nginx-v2 created

4) establish Nginx Project Service resources

Two versions of Nginx Pod Resources are connected to Service Resources , Although both the online version and the beta version have been added to Service Resources , But we will be VirtualService Resources , Will not affect the use of online programs .

1. Generate service Resource orchestration file 
[[email protected]-master myproject]# kubectl expose deployment nginx-v1 --port=80 --target-port=80 -n istio-project --dry-run -o yaml > nginx-service.yaml

2. Configure resource orchestration file 
[[email protected]-master myproject]# vim nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: istio-project
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
    version: v1

3. up to now Nginx Project and in K8S The deployment in the cluster is completed and connected to Istio in 
[[email protected]-master myproject]# kubectl get all -n istio-project
NAME                            READY   STATUS    RESTARTS   AGE
pod/nginx-v1-69d9ddb5cb-httvf   2/2     Running   0          19m
pod/nginx-v2-744c97bc9-8nk6d    2/2     Running   0          19m

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
service/nginx   ClusterIP   10.111.48.212   <none>        80/TCP    35s

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-v1   1/1     1            1           19m
deployment.apps/nginx-v2   1/1     1            1           19m

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-v1-69d9ddb5cb   1         1         1       19m
replicaset.apps/nginx-v2-744c97bc9    1         1         1       19m

4. see Service Resources are associated with Pod resources 
[[email protected]-master myproject]# kubectl get ep -n istio-project 
NAME        ENDPOINTS                             AGE
nginx-svc   100.111.156.83:80,100.64.169.143:80   45s

#Service Two versions of the program are added to the resource , But the user's request will not arrive V2 edition , We will implement it in VirtualService To configure .

2.2. establish Nginx Project DestinationRule resources

1. Write a resource orchestration file 
[[email protected]-master myproject]# vim nginx-destinationrule.yaml 
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: nginx-dr
  namespace: istio-project  
spec:
  host: nginx-svc			# relation Nginx Of Service resources 
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

2. Create resources 
[[email protected]-master myproject]# kubectl apply -f nginx-destinationrule.yaml
destinationrule.networking.istio.io/nginx-dr created

3. View the status of resources 
[[email protected]-master myproject]# kubectl get dr -n istio-project
NAME       HOST        AGE
nginx-dr   nginx-svc   3s

2.3. establish Nginx Project Gateway resources

1. Orchestrate resources orchestrate files 
[[email protected]-master myproject]# vim nginx-gateway.yaml 
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: nginx-gateway
  namespace: istio-project
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
    
2. Create resources 
[[email protected]-master myproject]# kubectl apply -f nginx-gateway.yaml
gateway.networking.istio.io/nginx-gateway created

2.4. establish Nginx Project VirtualService resources

1. Write a resource orchestration file 
[[email protected]-master myproject]# cat nginx-virtualservice.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nginx-vs
  namespace: istio-project
spec:
  hosts:
  - "*"
  gateways:
  - nginx-gateway			# relation nginx Of gateway
  http:
  - route:
    - destination:
        host: nginx-svc				# relation nginx Of service resources 
        subset: v1					# Distribute all traffic to V1 Version of the program 
      weight: 100					# The ratio is 100%
    mirror:								# Define traffic mirroring 
      host: nginx-svc				# relation Nginx Of Service resources 
      subset: v2					# Copy traffic to v2 Version of the program 
    mirror_percent: 100				# The proportion of traffic replication is 100% Copy all  
# The final meaning : All online traffic has V1 Version processing , At the same time, copy a request to V2 edition , It does not affect the online use 

2.5. Test the function of traffic image

Browser access V1 edition , Observe V2 Whether the version will have and V1 Requests with the same version .
 Insert picture description here

Observe V1 and V2 Version of the access log , You will find that users access online V1 All request traffic for the version will be Istio Make a full copy to V2 Test version of , In the log X-Forword-For In the field, you can clearly see that an IP Address , This IP The address is Istio Of IngressGateway The address of , from IngressGateway Copy traffic to V2 In the program .

 Insert picture description here

原网站

版权声明
本文为[Jiangxl~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221236587998.html