OpenShift Istio-Tutorial 4 of (4) gray release a new version microService

This series OpenShift Servic Mesh tutorial is based on Red Hat official public offering " Introducing Istio Service Mesh for Micoservices " publication, I will verify all operations carried out in OpenShift 4.2.x environment. Like to read or need to learn more English and knowledge of the relevant scene small partners can download the book by reading the above slowly.

This section we deploy a new version of the micro-services, then based Istio flow control functions to achieve the gray release micro-switch version upgrade service. Gray scale can be achieved through different scenarios of flow control mechanism VirtualService release, we achieved the following two gray-scale release.

Posted flow proportional gray

  1. recommendation deployment v2 version of the micro-services, then confirm the progress of the deployment.
$ oc apply -f  recommendation/kubernetes/Deployment-v2.yml 
$ oc get pod
NAME                                 READY   STATUS    RESTARTS   AGE
customer-77dc47d7f8-szhd5            2/2     Running   1          44m
preference-v1-55476494cf-xm4dq       2/2     Running   0          44m
recommendation-v1-67976848-4l4s7     2/2     Running   0          44m
recommendation-v2-599867df6c-5ccdx   2/2     Running   0          38s
  1. Execute commands to access micro customer service (do not stop the continuous access to the micro customer service), since no set forward strategy recommendation, so the request is sent in rotation recommendation-v1 and recommendation-v2.
$ ./scripts/run.sh http://${INGRESS_GATEWAY}/customer
customer => preference => recommendation v2 from '3cbba7a9cde5': 1
customer => preference => recommendation v1 from '67976848-4l4s7': 96
customer => preference => recommendation v2 from '3cbba7a9cde5': 2
customer => preference => recommendation v1 from '67976848-4l4s7': 97
customer => preference => recommendation v2 from '3cbba7a9cde5': 3
customer => preference => recommendation v1 from '67976848-4l4s7': 98
...
  1. And then create VirtualService DestinationRule recommendation named object named following the recommendation of a new command in the command window, to achieve 100% of the request sent to the recommendation-v2.
    VirtualService defined object istiofiles / virtual-service-recommendation- v2.yml in. Wherein "subset: version-v2" corresponding to the object behind DestinationRule "name: version-v1" to "subset".
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService                    
metadata:                               
  name: recommendation                  
spec:                                   
  hosts:                                
  - recommendation                      
  http:                                 
  - route:                              
    - destination:                      
        host: recommendation           # host对应的recommendation的Service的url,可以是short或long的url
        subset: version-v2             # subset对应的是DestinationRule中的subset名称,DestinationRule会按照这个lable找到对应的pod
      weight: 100

DestinationRule defined object istiofiles / destination-rule-recommendation-v1-v2.yml in.

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: recommendation
spec:
  host: recommendation
  subsets:
  - labels:
      version: v1					# DestinationRule会按照这个lable找到对应的pod
    name: version-v1
  - labels:
      version: v2
    name: version-v2                 

Execute the following commands are created VirtualService and DestinationRule, Note : After running only the first command creates VirtualService, the first window will complain "the Customer => Error: 500 - ErrorInternal Server Error", which is due to VirtualService use not found subnet, this subnet is defined in DestinationRule in.

$ oc apply -f istiofiles/virtual-service-recommendation-v2.yml
$ oc apply -f istiofiles/destination-rule-recommendation-v1-v2.yml

Note:
4. View first command window, the output from the confirmation request is sent to both the version v2 micro recommendation service.

customer => preference => recommendation v2 from '3cbba7a9cde5': 24
customer => preference => recommendation v2 from '3cbba7a9cde5': 25
customer => preference => recommendation v2 from '3cbba7a9cde5': 26
...
  1. In the second window execute the following command to forward the request to all of the v1 version of the micro recommendation service.
$ oc apply -f istiofiles/virtual-service-recommendation-1.yml
  1. View first command window, all output from the confirmation request is sent to the v1 version of the recommendation on the micro-services.
customer => preference => recommendation v1 from '67976848-4l4s7': 859
customer => preference => recommendation v1 from '67976848-4l4s7': 860
customer => preference => recommendation v1 from '67976848-4l4s7': 861
...
  1. Run the following commands in the second window in accordance with the request: the ratio of "91" is sent to the micro-v1 recommendation service version and the version V2 micro recommendation service.
    Distribution policies defined in istiofiles / virtual-service-recommendation- v1_and_v2.yml in.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: recommendation
spec:
  hosts:
  - recommendation
  http:
  - route:
    - destination:
        host: recommendation
        subset: version-v1
      weight: 90
    - destination:
        host: recommendation
        subset: version-v2
      weight: 10

Execute commands, update VirtualService strategy.

$ oc apply -f istiofiles/virtual-service-recommendation-v1_and_v2.yml
  1. Run the following commands in the second window in accordance with the request: the ratio of "31" is sent to the micro-v1 recommendation service version and the version V2 micro recommendation service.
$ oc apply -f istiofiles/virtual-service-recommendation-v1_and_v2_75_25.yml
  1. In the first command window termination run.sh run.

Press release request header gray

By forwarding the request VirtualService allocation strategy, we can also implement other complex scenarios, where the gray release is a common scene.

Gray publish in accordance with browser vendors

  1. Policies defined in istiofiles / virtual-service-safari-recommendation-v2.yml is to let the Safari browser to access a recommendation v2 version of the micro-services, and other browsers visit is v1 version of the recommendation.
apiVersion: networking.istio.io/v1alpha3 
kind: VirtualService                     
metadata:                                
  name: recommendation                   
spec:                                    
  hosts:                                 
  - recommendation                       
  http:                                  
  - match:                               
    - headers:                           
        baggage-user-agent:              
          regex: .*Safari.*              
    route:                               
    - destination:                       
        host: recommendation             
        subset: version-v2               
  - route:                               
    - destination:                       
        host: recommendation             
        subset: version-v1               

Execute commands to modify VirtualService strategy.

$ oc apply -f istiofiles/virtual-service-safari-recommendation-v2.yml
  1. Analog transmission Safari browser and Firefox browser request, return results confirmed. Safari browser which is accessible recommendation v2 version of the micro-services, while Firefox browser to access it in the v1 version of the recommendation.
$ curl -A Safari $INGRESS_GATEWAY/customer
$ curl -A Firefox $INGRESS_GATEWAY/customer

Gray published by browser type

  1. Execute commands modify VirtualService strategy so that mobile browser to access a recommendation v2 version of the micro-services, and other browsers visit is v1 version of the recommendation.
$ oc apply -f istiofiles/virtual-service-mobile-recommendation-v2.yml 
  1. Analog transmission and mobile browsers in general request, return results confirmed.
$ curl -A "Mozilla/5.0 Version/5.0.2 Mobile/8J2 Safari" $INGRESS_GATEWAY/customer
$ curl $INGRESS_GATEWAY/customer
Published 54 original articles · won praise 0 · Views 1012

Guess you like

Origin blog.csdn.net/weixin_43902588/article/details/103976437