Chapter XXI nine analysis with you easily after blasting service mesh - Istio routing rules

Series:


Index List: nine analyze with you easily complete explosion istio Service Grid Tutorial Series

table of Contents

1 Introduction

2 offer

3 Routing Rule Syntax

4 Routing Rule Priority

5 Routing Rule matching rules / conditions

    5.1 Based on HttpMatchRequest

    5.2 based on the weight

6 Flow Operation (HTTPRoute)


1 Introduction

        If you have any questions about the blog, please let me know.1.png


2 offer

        You can search from the station b "Nine Analysis" to get a free, more vivid video material:clipboard2.png


3 Routing Rule Syntax

        In the last section describes the concept of Virtual Service and run a simple example, we should have a general understanding of the Virtual Service.

        Virutal Service is the most important concept is the routing rules (Routing Rule), note with another concept Istio traffic management - The destination rule (Destination Rule) distinction, the former is a logical concept, while the latter, like Virtual Service, the actual resources can be deployed to Istio on K8S.

        Before explaining routing rules here to give an example:

        Went to the peak of recruitment, HR succession campus recruitment of a number of graduates. After hiring these graduates to be assigned to specific jobs. Allocation rules are as follows:

First, the 986 school graduates assigned to the base platform group

Second, the general school graduates assigned to the trading platform group

Third, the dark horse programmer graduate students assigned to the operation and maintenance of the platform group

        Examples of the above mentioned two concepts. A: matching rule (or match condition); II: route to the destination. In fact, this is the protagonist of this section describes the Routing Rule, Routing Rule two words on the perfect contains two concepts above.

Then again look at the code below, to deepen understanding about:clipboard3.png

        The syntax is simple as explained below, the effect is routed to the matching rules XX OO, if you do not match the rules on routes to SY (if ... else ... a little taste):

match...route destination.../ route destination ...

        Of course, there is one thing needs to be clarified is that the matching condition is not mandatory, that the routing rules do not have to have a match (match), the only route is also possible.

        Look at the use cases CHAPTER run my design, run and the results shown in the following screenshot:clipboard4.png


4 Routing Rule Priority

        Routing rules from top to bottom in order to assess, wherein the first routing rules defined in the Virtual Service has the highest priority. Of course, we recommended here provide a default "unconditional" or rules based on the weight (weight) in each virtual service as a final rule to ensure that traffic to the virtual service always has at least one matching route.


5 Routing Rule matching rules / conditions

5.1 Based on HttpMatchRequest

        Matching rules / conditions from the keyword match began, for certain matching conditions, can choose to use the exact value (exact), prefix (prefix) or regular expressions to select them. For a complete list of matching criteria fields and their possible values can be found in HTTPMatchRequest found.

        http sample resource file as the matching condition, the sample specified in the request uri ignoring case, if the prefix / ratings / v2 /, and the end-user in the http header field is Jason, on the route to the named space for the name of the prod for ratings services to:

apiVersion: networking.istio.io/v1alpha3

kind: VirtualService

metadata:  

    name: ratings-route

spec:  

    hosts:  

    - ratings.prod.svc.cluster.local  

    http:  

    - match:    

       - headers:        

            end-user:          

                exact: jason      

          hate:        

            prefix: "/ratings/v2/"      

          ignoreUriCase: true    

       route:    

       - destination:        

            host: ratings.prod.svc.cluster.local

5.2 based on the weight

        In addition to routing rules based on HTTPMatchRequest match, also it is based on weight (weight), by weight can easily after blasting A / B testing and Canary (Canary) was released. Weight settings are as follows:

apiVersion: networking.istio.io/v1alpha3

kind: VirtualService

metadata:

    name: web-vs-svc

spec:

    hosts:

    - web-svc

    http:

    - route:

        - destination:

            host: httpd-svc

            weight: 20

        - destination:

            host: tomcat-svc

            weight: 80


6 Flow Operation (HTTPRoute)

        Routing rules can be used to do some traffic operations:

In addition or deletion title

URL Rewrite

Set retry strategy for the route to the destination

        For example, the flow rate operation is as follows:

apiVersion: networking.istio.io/v1alpha3

kind: VirtualService

metadata:

    name: web-vs-svc

spec:

    hosts:

    - web-svc

    http:

    - match:

       - Sites:

            prefix: /index.html

          rewrite:

            tags: /index.html

          route:

          - destination:

                host: tomcat-svc

        For more information on traffic operations, refer to HTTPRoute .

        Since then, nine analyze with you easily complete explosion Istio routing rules.

Guess you like

Origin blog.51cto.com/14625168/2486095