All Products
Search
Document Center

Alibaba Cloud Service Mesh:mirrored traffic

Last Updated:Dec 01, 2025

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 mocka and sleep services are deployed. For more information, see Preparations.

Procedure

  1. Check whether the service configurations take effect.

    1. In the kubeconfig environment for your ACK cluster, run the following command to start a bash session in the sleep environment:

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

      curl mocka:8000/mock

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

      -> mocka(version: v1, ip: 192.168.1.246)
      -> mocka(version: v2, ip: 192.168.1.53)
  2. Configure a traffic rule for the mocka service, configure mocka-v1 to receive and respond to requests, and mirror the requests to mocka-v2.

    1. 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: mocka
        namespace: default
      spec:
        hosts:
          - mocka
        http:
          - match:
              - uri:
                  exact: /mock
            mirror:
              host: mocka-v2
            route:
              - destination:
                  host: mocka-v1
  3. Check whether the configurations take effect.

    1. In the kubeconfig environment for your ACK cluster, run the following command to start a bash session in the sleep environment:

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

      curl mocka:8000/mock

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

      -> mocka(version: v1, ip: 192.168.1.246)
    3. Run the following commands to view the logs of mocka-v2:

      kubectl logs deployments/mocka-v2

      Expected output:

      receive request: x-request-id: 6f11e7b9-dc6c-4e57-aa52-c2644f8d****
      receive request: x-request-id: e9cedc48-d5c1-4233-a97b-5cb88f0d****
      receive request: x-request-id: bf4e4bb2-7339-42a0-a70f-eab7905d****
      receive request: x-request-id: 4779fb9a-f9c5-47c2-b9f7-8dc097cd****
      receive request: x-request-id: f32f012a-669d-48a4-a992-473068dd****
      receive request: x-request-id: 3ef4a1e7-4301-45db-ad1c-6b35bd1d****
      ...

      The output indicates that mocka-v2 also receives the requests. If requests are continuously sent to mocka-v1, the logs of mocka-v2 indicate that mocka-v2 receives requests continuously.