All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure mirroring

Last Updated:Oct 11, 2023

You can use Service Mesh (ASM) to send a copy of traffic destined for a service to a mirrored service. This topic describes how to configure mirroring.

Prerequisites

The preparations are completed, and the helloworld and sleep services are deployed. For more information, see Preparations.

Procedure

  1. Check whether the service configurations take effect.

    1. Use kubectl to connect to the Container Service for Kubernetes (ACK) cluster based on the information in the kubeconfig file, and then run the following command to enable bash for the sleep service:

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request to the helloworld service:

      curl helloworld:5000/hello

      Expected output:

      Hello version: v2, instance: helloworld-v2-6b96c5684-4****
      Hello version: v1, instance: helloworld-v1-6d77f4c4cf-p****

      The expected output is that helloworld-v1 or helloworld-v2 randomly responds to the request.

  2. Configure a traffic rule for the helloworld service, configure helloworld-v1 to receive and respond to requests, and mirror the requests to helloworld-v2.

    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. For more information, see Manage virtual services.

      apiVersion: networking.istio.io/v1beta1
      kind: VirtualService
      metadata:
        name: helloworld-vs
        namespace: default
      spec:
        hosts:
          - helloworld
        http:
          - mirror:
              host: helloworld
              subset: v2
            route:
              - destination:
                  host: helloworld
                  subset: v1
  3. Check whether the configurations take effect.

    1. Use kubectl to connect to the ACK cluster based on the information in the kubeconfig file, and then run the following command to enable bash for the sleep service:

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request to the helloworld service:

      curl helloworld:5000/hello

      The expected output is always that helloworld-v1 responds to the request.

      Hello version: v1, instance: helloworld-v1-6d77f4c4cf-p****
    3. View the topology of the service. For more information, see Use Mesh Topology to view the topology of an application.

      Expected output: The request is copied to helloworld-v2.

      查看应用网格拓扑.png