[Failover] Traffic Degradation

Updated at:

When the target service of a request has no available endpoints, traffic degradation degrades and forwards the request to another group of service endpoints that you specify in advance. This topic describes how to configure traffic degradation.

Prerequisites

The preparations are complete, and the helloworld service and the sleep service are deployed. For more information, see Preparations.

Procedure

  1. Use the following content to configure a destination rule. For more information, see Manage destination rules.

    apiVersion: networking.istio.io/v1beta1
    kind: DestinationRule
    metadata:
      name: helloworld
      namespace: default
    spec:
      host: helloworld
      subsets:
        - labels:
            version: v1
          name: v1
        - labels:
            version: v2
          name: v2
    
  2. Use the following content to create a virtual service that routes all requests sent to the helloworld service to the v1 subset of helloworld. When the v1 subset has no available endpoints, requests are degraded to the v2 subset of the helloworld service. For more information, see Manage virtual services.

  3. apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: helloworld
    spec:
      hosts:
        - helloworld
      http:
        - route:
            - destination:
                host: helloworld
                subset: v1
              fallback:
                target:
                  host: helloworld
                  subset: v2
    
  4. Verify whether traffic degradation takes effect.

    1. In the KubeConfig environment of the ACK cluster, run the following command.

      kubectl exec deploy/sleep -- sh -c "for i in \$(seq 1 100); do curl -s http://helloworld:5000/hello; done"

      Expected output:

      Hello version: v1, instance: helloworld-v1-9585666c8-8****
      Hello version: v1, instance: helloworld-v1-9585666c8-8****
      Hello version: v1, instance: helloworld-v1-9585666c8-8****
      Hello version: v1, instance: helloworld-v1-9585666c8-8****
      ...
      Hello version: v1, instance: helloworld-v1-9585666c8-8****

      The expected output indicates that when the v1 subset of the helloworld service exists, all requests are sent to the v1 subset of the helloworld service.

    2. Scale in the v1 subset of the helloworld service to 0 to simulate a failure.

      1. Log on to the ACK console. In the left navigation pane, click Clusters.

      2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Workloads > Deployments.

      3. On the Deployments page, in the Actions column, click Scale for the helloworld-v1 workload. In the Scale dialog box, set Desired Pod Count to 0, and then click OK.

    3. In the KubeConfig environment of the ACK cluster, run the following command to verify access to the helloworld service again.

      kubectl exec deploy/sleep -- sh -c "for i in \$(seq 1 100); do curl -s http://helloworld:5000/hello; done"

      Expected output:

      Hello version: v2, instance: helloworld-v2-68bb8c995b-t****
      Hello version: v2, instance: helloworld-v2-68bb8c995b-t****
      ...
      Hello version: v2, instance: helloworld-v2-68bb8c995b-t****
      Hello version: v2, instance: helloworld-v2-68bb8c995b-t****
      Hello version: v2, instance: helloworld-v2-68bb8c995b-t****

      The expected output indicates that when the v1 subset of the helloworld service has no available endpoints, all requests are sent to the v2 subset of the service, and traffic degradation takes effect.