istio service tracking and traffic management

Creating goals rule and a default route

Use Istio to manage the flow of these two services

Define a name for nginx-web of DestinationRule goals rule,

Pod tag using the nginx-web service into two subset, named v1 and v2

# nginx-destinationRule.yaml 
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: nginx-web
spec:
  host: nginx-web
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
      
      
#### 部署到集群上

 kubectl apply -f nginx-destinationRule.yaml          
Creates a default routing rules VirtualService whether further flow control, suggest creating a default routing rules for the grid service

Define a VirtualService object, which is responsible for taking over access to the "nginx-web" the host name,
the traffic will be forwarded to the definition of v2 subset DestinationRule

# cat nginx-virtual-service-reviews-v2.yaml 
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nginx-web-v2
spec:
  hosts:
    - nginx-web
  http:
  - route: 
    - destination: 
        host: nginx-web
        subset: v2

#### 部署到集群上
kubectl apply -f nginx-virtual-service-reviews-v2.yaml 

Pod into the client again to see the new traffic management rules defined is in effect

### 结果可以看出,访问只返回 v2 版本
# kubectl exec -it sleep-7995b95fdb-8vzmx sh
Defaulting container name to sleep.
Use 'kubectl describe pod/sleep-7995b95fdb-8vzmx -n default' to see all of the containers in this pod.
/ # while true; do curl http://nginx-web:80 ; sleep 1; done
<h1>Welcome to V2 !</h1>
<h1>Welcome to V2 !</h1>
<h1>Welcome to V2 !</h1>
<h1>Welcome to V2 !</h1>

Canary deployment

Canary (Canary) deployment refers to the small number of users use the application to make a new version of the process,
by means of this process can verify that the new version if there are problems, then release to ensure a higher quality to a wider audience
20% the user is sent to the v2 version with defect (which is canary release),
and sends 80% of users to normal service v1 version of
this can be achieved by following VirtualService

# cat nginx-virtual-service-reviews-80-20.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nginx-web
spec:
  hosts:
    - nginx-web
  http:
  - route: 
    - destination: 
        host: nginx-web
        subset: v1
      weight: 80
    - destination: 
        host: nginx-web
        subset: v2
      weight: 20

#### 部署到集群上
kubectl apply -f nginx-virtual-service-reviews-80-20.yaml

Pod into the client again to see the new traffic management rules defined is in effect

### 结果可以看出,大部分结果返回 v1 版本
# kubectl exec -it sleep-7995b95fdb-8vzmx sh
Defaulting container name to sleep.
Use 'kubectl describe pod/sleep-7995b95fdb-8vzmx -n default' to see all of the containers in this pod.
/ # while true; do curl http://nginx-web ; sleep 1; done
<h1>Welcome to V1 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V2 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V1 !</h1>
<h1>Welcome to V2 !</h1>

Service with a defective version of the probability there will be a third of the cost in generating response time is too long,
one-third probability server encountered an internal error, the rest of the request can be completed normally.

In order to reduce the impact of these defects and to give users a better user experience, we will take the following measures:

  • If the service takes more than eight seconds, it will time out;
  • To retry the request failed.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nginx-web
spec:
  hosts:
    - nginx-web
  http:
  - route: 
    - destination: 
        host: nginx-web
        subset: v1
      weight: 80
    - destination: 
        host: nginx-web
        subset: v2
      weight: 20
    timeout: 8s
    retries:
      attempts: 3
      perTryTimeout: 3s

Guess you like

Origin blog.csdn.net/u011327801/article/details/91047188