All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure mirroring

Last Updated:Oct 16, 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 mocka 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 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. Use the istioctl tool to run the following command to deploy a Layer 7 waypoint proxy for the mocka service:

    istioctl x waypoint apply --service-account mocka
  3. 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 destination rule. For more information, see Manage destination rules.

      apiVersion: networking.istio.io/v1beta1
      kind: DestinationRule
      metadata:
        name: mocka
        namespace: default
      spec:
        host: mocka
        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: mocka
        namespace: default
      spec:
        hosts:
          - mocka
        http:
          - match:
              - uri:
                  exact: /mock
            mirror:
              host: mocka
              subset: v2
            route:
              - destination:
                  host: mocka
                  subset: v1
  4. 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 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:

      # View the name of the mocka-v2 Pod: 
      kubectl get pods 
      # View the logs of the mocka-v2 pod: 
      kubectl logs {Name of the mocka-v2 pod}

      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.