Skip to main content
In this lesson we configure traffic mirroring with Istio. Traffic mirroring lets you send a copy of live requests to a secondary subset (for testing, canary analysis, logging, or debugging) while the primary subset continues to serve real user traffic.
Make sure the namespace where you deploy your workloads has Istio sidecar injection enabled. Istio features (including mirroring) require injection to be active for the namespace.
Overview:
  • Primary goal: route 100% of client traffic to v1 while mirroring copies of those requests to v2.
  • Components used: Kubernetes Deployments, Service, Istio DestinationRule and VirtualService.
  • Key Istio concepts: subsets (DestinationRule), mirror and mirrorPercentage (VirtualService).

1. Verify namespace injection

Confirm which namespaces have Istio sidecar injection enabled:
Sample output:
If the target namespace is not labeled with istio-injection=enabled, enable injection before deploying the workloads.

2. Deploy two echo-server versions (v1 and v2)

Create a single YAML containing two Deployments: echo-server-v1 and echo-server-v2. Both share app: echo-server but use different version labels so Istio can create subsets that map to those versions.
Apply and verify the pods and labels:
Sample output (labels show app=echo-server and version):

3. Create a Service for the echo servers

Expose both versions through a ClusterIP Service that selects on app: echo-server so client traffic can reach either subset depending on routing rules.
Apply and confirm the service:
Sample output:

4. Tail logs for both versions

Open two terminals (or background one process) and stream logs from each pod to observe how mirrored requests appear in the mirror target. Terminal A (v1):
Sample v1 log lines:
Terminal B (v2):
Sample v2 log lines:
Keep these logs visible while you generate traffic so you can correlate client requests to backend activity.

5. Create a test pod to generate traffic

Run a small pod you can exec into for curl-based testing:
From inside the test pod, call the echo service repeatedly and extract the responding pod hostname. The echo server returns JSON with a hostname field; use grep and sed to print it cleanly:
Example outputs will indicate which backend served each request:
Watch the logs from step 4 to see mirrored requests appear in v2 while responses come from v1.

6. Define DestinationRule with subsets

Create an Istio DestinationRule that defines v1 and v2 subsets based on the version pod label. These subsets allow VirtualService routing rules to target specific versions.
Apply and verify:
Sample output:

7. Create a VirtualService that mirrors traffic

The VirtualService below routes 100% of production traffic to subset v1 and mirrors each request to subset v2. mirrorPercentage.value accepts a float between 0.0 and 100.0 so you can partially mirror traffic if desired.
Apply the VirtualService:
Tip: to reduce resource usage during testing, set mirrorPercentage.value to a lower number (for example 10.0) to mirror only 10% of requests.

8. Test mirrored traffic

From the test pod, run repeated curl commands and observe that client responses continue to come from v1 while v2 receives mirrored copies (visible in its logs). Repeat the same curl command:
Expected client responses (all real responses from v1 when routing is 100% to v1):
Meanwhile, check the v2 logs — you should see similar GET entries for the mirrored requests even though the client never received responses from v2. This confirms mirroring is functioning: real traffic is served by v1, and duplicates are sent to v2 for analysis or testing. Example request log from v1:
Example mirrored request log in v2:

Quick reference table

Notes and references

  • Mirroring does not change the client response; it only sends a copy of the request to the mirror target.
  • Use mirrorPercentage to limit the portion of requests that are mirrored (0.0–100.0).
  • Ensure labels in DestinationRule.subsets exactly match pod labels (version: v1 / version: v2).
  • Mirroring is useful for testing new versions without impacting users: logs, tracing, or metrics from the mirror can validate behavior.
If you need the Gateway API or other CRDs present, ensure any required CRDs are installed before testing; for example, follow upstream installation instructions for the Gateway API when required by your environment.
Links and references: That completes this lesson on Istio traffic mirroring. Try adjusting mirrorPercentage and subsets to experiment with partial mirroring and canary analysis in your cluster.

Watch Video

Practice Lab