< img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=3131724&fmt=gif" />

Traffic Mirroring

Traffic mirroring, also called shadowing, is a powerful, risk-free method of testing your app versions as it sends a copy of live traffic to a service that is being mirrored. Namely, you implement a similar setup for acceptance test so that problems can be detected in advance. As mirrored traffic happens out of band of the critical request path for the primary service, your end users will not be affected during the whole process.


Create a Traffic Mirroring Job

  1. Log in to KubeSphere as project-regular and go to Grayscale Release. Under Release Modes, click Create on the right of Traffic Mirroring.

  2. Set a name for it and click Next.

  3. On the Service Settings tab, select your app from the drop-down list and the Service of which you want to mirror the traffic. If you also use the sample app Bookinfo, select reviews and click Next.

  4. On the New Version Settings tab, add another version of it (for example, kubesphere/examples-bookinfo-reviews-v2:1.16.2; change v1 to v2) and click Next.

  5. On the Strategy Settings tab, click Create.

  6. The traffic mirroring job created is displayed under the Release Jobs tab. Click it to view details.

  7. You can see the traffic is being mirrored to v2 with real-time traffic displayed in the line chart.

  8. The new Deployment is created as well.

  9. You can get the virtual service to view mirror and weight by running the following command:

    kubectl -n demo-project get virtualservice -o yaml


    • When you run the command above, replace demo-project with your own project (namely, namespace) name.
    • If you want to run the command from the web kubectl on the KubeSphere console, you need to use the user admin.
  10. Expected output:

      - reviews
      - route:
        - destination:
            host: reviews
              number: 9080
            subset: v1
          weight: 100
          host: reviews
            number: 9080
          subset: v2

    This route rule sends 100% of the traffic to v1. The mirror field specifies that you want to mirror to the service reviews v2. When traffic gets mirrored, the requests are sent to the mirrored service with their Host/Authority headers appended with -shadow. For example, cluster-1 becomes cluster-1-shadow.


    These requests are mirrored as “fire and forget”, which means that the responses are discarded. You can specify the weight field to mirror a fraction of the traffic, instead of mirroring all requests. If this field is absent, for compatibility with older versions, all traffic will be mirrored. For more information, see Mirroring.

Take a Job Offline

You can remove the traffic mirroring job by clicking Delete, which does not affect the current app version.

Receive the latest news, articles and updates from KubeSphere

Thanks for the feedback. If you have a specific question about how to use KubeSphere, ask it on Slack. Open an issue in the GitHub repo if you want to report a problem or suggest an improvement.