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.

Prerequisites

Create a Traffic Mirroring Job

  1. Log in to KubeSphere as project-regular. Under Categories, click Create Job on the right of Traffic Mirroring.

    traffic-mirroring-1

  2. Set a name for it and click Next.

    traffic-mirroring-2

  3. 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.

    traffic-mirroring-3

  4. On the Grayscale Release Version page, add another version of it (e.g. v2) as shown in the image below and click Next:

    traffic-mirroring-4

    Note

    The image version is v2 in the screenshot.

  5. Click Create in the final step.

    traffic-mirroring-5

  6. The traffic mirroring job created displays under the tab Job Status. Click it to view details.

    traffic-mirroing-task

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

    traffic-mirroring-6

  8. The new Deployment is created as well.

    new-deployment

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

    1. kubectl -n demo-project get virtualservice -o yaml

    Note

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

    1. ...
    2. spec:
    3. hosts:
    4. - reviews
    5. http:
    6. - route:
    7. - destination:
    8. host: reviews
    9. port:
    10. number: 9080
    11. subset: v1
    12. weight: 100
    13. mirror:
    14. host: reviews
    15. port:
    16. number: 9080
    17. subset: v2
    18. ...

    This route rule sends 100% of the traffic to v1. The last stanza 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.

    Note

    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 Job offline, which does not affect the current app version.

remove-traffic-mirroring