OpenShift Service 4 of Mesh Tutorial (5) - to access back-end services to track overtime

This article explains how to set up access in Istio in VirtualService the timeout feature. Each request sent to the background, and backend-v1 backend-v2 micro services, backend-v2 will return more than 3 seconds, and therefore time out.
Here Insert Picture Description
After the operation - "Kiali monitoring service run by micro OpenShift Service 4 of Mesh Tutorial (3)" article can be completed. Need to run before the official start of the operation the following command to run my-istio-app project applications to empty the contents.

$ scripts/teardown.sh
  1. Deploy the image above frontend-v1 and backend-v1 micro-services, and related services.
$ oc apply -f ocp/frontend-v1-deployment.yml -n my-istio-app
$ oc apply -f ocp/frontend-service.yml -n my-istio-app
$ oc apply -f ocp/frontend-route.yml -n my-istio-app
$ oc apply -f ocp/backend-v1-deployment.yml -n my-istio-app
$ oc apply -f ocp/backend-service.yml -n my-istio-app

Confirm backend-v1-deployment.yml access is v1 version of the backend application.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: backend-v1
  # labels:
  #   app: backend
  #   version: v1
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: backend
        version: v1
      annotations:
        sidecar.istio.io/inject: "true"
    spec:
      containers:
      - name: backend
        image: quay.io/voravitl/backend-js:v1
        imagePullPolicy: Always
        resources:
          requests:
            cpu: "0.1"
            memory: 60Mi
          limits:
            cpu: "0.2"
            memory: 100Mi
        env:
          - name: BACKEND_URL
            value: https://httpbin.org/status/200
        ports:
        - containerPort: 8080
  1. Run command, confirmed the results can be accessed from the return to service micro-backend-v1.
$ curl $FRONTEND_URL
Frontend version: v1 => [Backend: http://backend:8080, Response: 504, Body: upstream request timeout]
  1. Run the command send test request.
$ scripts/run-50.sh
...
$ Backend:v1, Response Code: 200, Host:backend-v1-6ddf9c7dcf-pppzc, Elapsed Time:0.774024 sec
Backend:, Response Code: 504, Host:, Elapsed Time:3.193873 sec
Backend:v1, Response Code: 200, Host:backend-v1-6ddf9c7dcf-pppzc, Elapsed Time:0.787584 secBackend:, Response Code: 504, Host:, Elapsed Time:3.724406 sec
Backend:, Response Code: 504, Host:, Elapsed Time:3.147017 sec
Backend:, Response Code: 504, Host:, Elapsed Time:3.207459 sec
========================================================
Total Request: 50
Version v1: 25
Version v2: 0
========================================================
  1. To view micro-services in Kiali console access request chain and response time.
    Here Insert Picture Description
  2. Run deploy backend-v2 micro services.
$ oc apply -f ocp/backend-v2-deployment.yml -n my-istio-app

Confirm backend-v2-deployment.yml access is v2 version of the backend application.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: backend-v2
  # labels:
  #   app: backend
  #   version: v2
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: backend
        version: v2
      annotations:
        sidecar.istio.io/inject: "true"
    spec:
      containers:
      - name: backend
        image: quay.io/voravitl/backend-js:v2
        imagePullPolicy: Always
        resources:
          requests:
            cpu: "0.1"
            memory: 60Mi
          limits:
            cpu: "0.2"
            memory: 100Mi
        env:
          - name: BACKEND_URL
            value: https://httpbin.org/delay/5
            #value: https://httpbin.org/status/503
        ports:
        - containerPort: 8080
  1. Run send test request to view the backend-v1 backend-v2 and response time. May be seen both in rotation back to access services, in response to the call backend-v1 relatively short (less than 3 seconds), the call backend-v2 response time is relatively long (greater than 3 seconds).
$ scripts/run-50.sh
...
Backend:v2, Response Code: 200, Host:backend-v2-7655885b8c-4l4xx, Elapsed Time:5.802549 sec
Backend:v1, Response Code: 200, Host:backend-v1-6ddf9c7dcf-kx7r7, Elapsed Time:0.799221 sec
Backend:v2, Response Code: 200, Host:backend-v2-7655885b8c-4l4xx, Elapsed Time:5.807315 sec
Backend:v1, Response Code: 200, Host:backend-v1-6ddf9c7dcf-kx7r7, Elapsed Time:0.830107 sec
Backend:v1, Response Code: 200, Host:backend-v1-6ddf9c7dcf-kx7r7, Elapsed Time:0.818900 sec
Backend:v2, Response Code: 200, Host:backend-v2-7655885b8c-4l4xx, Elapsed Time:5.823480 sec
...
  1. To view micro-services in Kiali console access request chain and response time.
    Here Insert Picture Description
  2. Execute command to create DestinationRule.
$ oc apply -f istio-files/destination-rule-backend-v1-v2.yml -n my-istio-app
  1. To view micro-service access request chain in Kiali console, this time requesting access path and (7) see is the same. This is because the destination-rule-backend-v1-v2.yml in DestinationRule only defined when ROUND_ROBIN distribution strategies backend-v1 and backend-v2 have run multiple instances of the pod, and request the backend-v1 and backend- in rotation between v2 are not defined by the above DestinationRule.
  2. Confirmed virtual-service-backend-v1-v2-50-50-3s-timeout.yml in VirtualService defined timeout to 3 seconds micro-services. Then execute the command to create a VirtualService.
$ oc apply -f istio-files/virtual-service-backend-v1-v2-50-50-3s-timeout.yml -n my-istio-app
  1. Run the hair test request. Backend-v2 can be seen that the response time is relatively long (greater than 3 seconds) have followed "Response Code: 504" processed.
$ scripts/run-50.sh
...
Backend:, Response Code: 504, Host:, Elapsed Time:3.008774 sec
Backend:, Response Code: 504, Host:, Elapsed Time:3.007154 sec
Backend:v1, Response Code: 200, Host:backend-v1-6ddf9c7dcf-kx7r7, Elapsed Time:1.078945 sec
Backend:v1, Response Code: 200, Host:backend-v1-6ddf9c7dcf-kx7r7, Elapsed Time:0.823204 sec
Backend:v1, Response Code: 200, Host:backend-v1-6ddf9c7dcf-kx7r7, Elapsed Time:0.824504 sec
Backend:, Response Code: 504, Host:, Elapsed Time:3.009229 sec
...
  1. To view micro-services in Kiali console access request chain and response time. Since the backend-v2 which sent requests time out and the system is marked in red.
    Here Insert Picture Description
Published 54 original articles · won praise 0 · Views 1077

Guess you like

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