OpenShift Istio-Tutorial (5) 4, and the other flow control scenarios of the relationship VirtualService and DestinationRule

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.

On a gray release may we understand how to implement traffic management, this section, we will introduce two other flow control functions Istio: traffic mirroring and traffic load balancing.

Traffic Mirroring

  1. Get run recommendation-v1 and recommendation-v2 instance name of the pod in the first command window.
$ oc get pod -n tutorial| grep recommendation
recommendation-v1-549bf5fcb9-zdxhd   2/2     Running   0          154m
recommendation-v2-599867df6c-5t2b7   2/2     Running   0          87m
  1. Run to view the container logs run micro-recommendation-v2 service in the first command window.
$ oc logs -f recommendation-v2-599867df6c-5t2b7 -c recommendation -n tutorial
  1. In the second modification command window Run VirtualService policy, the request sent to the recommendation-v1, and forward the image to the recommendation-v2.
    File istiofiles / virtual-service-recommendation- v1-mirror-v2.yml defines a mirror image of the forwarding policy.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: recommendation
spec:
  hosts:
  - recommendation
  http:
  - route:
    - destination:
        host: recommendation
        subset: version-v1
    mirror:
      host: recommendation
      subset: version-v2

Execute commands to modify VirtualService strategy recommendation of:

$ oc apply -f istiofiles/virtual-service-recommendation-v1-mirror-v2.yml -n tutorial
  1. Customer service request to the second micro-command window. At this time, the window can be seen that the request to "recommendation v1"
$ curl $INGRESS_GATEWAY/customer
customer => preference => recommendation v1 from '549bf5fcb9-zdxhd': 1924
  1. In the first command window you will also see the recommendation-v2日志有一行新纪录, indicating that the request is also forwarded to the recommendation-v2 mirrored micro service.
  2. Delete VirutalService object based on image strategy.
$ oc delete -f istiofiles/virtual-service-recommendation-v1-mirror-v2.yml -n tutorial

Service for traffic load balancing Pod

When a plurality of micro service instances or versions, if no Serivce defined DestinationRule, Serivce wheel in accordance with order (round-robin) manner request to its corresponding plurality of Pod. We can define DestinationRule object Serivce, in order to achieve load balancing strategy from the Service to the Pod.

  1. VirutalService object deletion step to create a mirror-based strategy. Note : At this point have no VirutalService for the recommendation of the.
$ oc delete -f istiofiles/virtual-service-recommendation-v1-mirror-v2.yml -n tutorial
$ oc get istio-io
NAME                                                 HOST             AGE
destinationrule.networking.istio.io/recommendation   recommendation   79m
NAME                                      AGE
gateway.networking.istio.io/customer-gw   21h
NAME                                             GATEWAYS        HOSTS   AGE
virtualservice.networking.istio.io/customer-vs   [customer-gw]   [*]     21h
  1. The micro-operation service recommendation-v2 Pod Example 3 increased.
$ oc scale deployment recommendation-v2 --replicas=3 -n tutorial
  1. Run command, view the request is forwarded to the micro-case recommendation service. At this time, the sequence number can be seen from the request is distributed under Pod instance in rotation.
./scripts/run.sh $INGRESS_GATEWAY/customer
customer => preference => recommendation v1 from '67976848-4l4s7': 1332
customer => preference => recommendation v2 from '3cbba7a9cde5': 82
customer => preference => recommendation v2 from '3cbba7a9cde5': 1
customer => preference => recommendation v2 from '3cbba7a9cde5': 1
customer => preference => recommendation v1 from '67976848-4l4s7': 1333
customer => preference => recommendation v2 from '3cbba7a9cde5': 83
customer => preference => recommendation v2 from '3cbba7a9cde5': 2
customer => preference => recommendation v2 from '3cbba7a9cde5': 2
...
  1. Run command to modify the load balancing strategy DestinationRule object is sent at random.
    File istiofiles / destination-rule-recommendation_lb_policy_app.yml configured to send all the random recommendation, whether it is recommendation-v1 or recommendation-v2, whether it is the pod instance.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: recommendation
spec:
  host: recommendation
  trafficPolicy:
    loadBalancer:
      simple: RANDOM

Execute commands to modify DestinationRule objects:

$ oc apply -f istiofiles/destination-rule-recommendation_lb_policy_app.yml -n tutorial
  1. Run command, view the request is forwarded to the micro-case recommendation service. From the sequence number may be randomly distributed to see the request recommendation Examples of different background.
./scripts/run.sh $INGRESS_GATEWAY/customer
customer => preference => recommendation v2 from '3cbba7a9cde5': 4
customer => preference => recommendation v1 from '67976848-4l4s7': 1420
customer => preference => recommendation v2 from '3cbba7a9cde5': 26
customer => preference => recommendation v1 from '67976848-4l4s7': 1421
customer => preference => recommendation v2 from '3cbba7a9cde5': 5
customer => preference => recommendation v2 from '3cbba7a9cde5': 6
customer => preference => recommendation v2 from '3cbba7a9cde5': 227
customer => preference => recommendation v1 from '67976848-4l4s7': 1422
customer => preference => recommendation v2 from '3cbba7a9cde5': 7
customer => preference => recommendation v2 from '3cbba7a9cde5': 228
customer => preference => recommendation v2 from '3cbba7a9cde5': 229
customer => preference => recommendation v2 from '3cbba7a9cde5': 8
customer => preference => recommendation v1 from '67976848-4l4s7': 1423
customer => preference => recommendation v1 from '67976848-4l4s7': 1424
customer => preference => recommendation v2 from '3cbba7a9cde5': 5
customer => preference => recommendation v2 from '3cbba7a9cde5': 230
customer => preference => recommendation v2 from '3cbba7a9cde5': 9
customer => preference => recommendation v1 from '67976848-4l4s7': 1425
customer => preference => recommendation v2 from '3cbba7a9cde5': 6
customer => preference => recommendation v2 from '3cbba7a9cde5': 10
customer => preference => recommendation v1 from '67976848-4l4s7': 1426
customer => preference => recommendation v1 from '67976848-4l4s7': 1427
customer => preference => recommendation v1 from '67976848-4l4s7': 1428
customer => preference => recommendation v1 from '67976848-4l4s7': 1429
customer => preference => recommendation v2 from '3cbba7a9cde5': 7
customer => preference => recommendation v2 from '3cbba7a9cde5': 231
customer => preference => recommendation v1 from '67976848-4l4s7': 1430
customer => preference => recommendation v2 from '3cbba7a9cde5': 232
...

The relationship VirtualService and DestinationRule

From the above operation we can see VirtualService DestinationRule objects and objects may be used alone or in combination. VirtualService One function is to select the function to forward a request to the rear end in different Service, Service and forwards the request to select a different Pod in the rear end. VirtualService and DestinationRule are linked together by subnet.
The second scenario herein, "Service for the traffic load balancing Pod" is independently DestinationRule, and VirtualService also be used independently, for example, following a request for a portion of the hair in the reviews.com dev.reviews.com.

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews-route-two-domains
spec:
  hosts:
  - reviews.com
  http:
  - route:
    - destination:
        host: dev.reviews.com
      weight: 25
    - destination:
        host: reviews.com
      weight: 75
Published 54 original articles · won praise 0 · Views 1060

Guess you like

Origin blog.csdn.net/weixin_43902588/article/details/103977999
Recommended