> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Mirroring

> Explains Istio traffic mirroring, including setup, VirtualService and DestinationRule examples, mirroring options, risks and best practices for safely testing new service versions with production requests.

Before configuring mirroring in Istio, it helps to understand common release strategies and how mirroring fits between them.

## Release strategies: Canary vs Blue–Green

A canary release introduces a new version gradually. The majority of users continue to use the stable v1 application while a small percentage is routed to the new version (v2). This limits blast radius while exposing the new version to real traffic.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/canary-release-kubernetes-ingress-90-10.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=984e9b2ba69ad691bb89c32a9d424cfb" alt="An infographic titled &#x22;Canary Release&#x22; showing a Kubernetes namespace where an Ingress Gateway routes 90% of traffic to Deployment V1 and 10% to Deployment V2, with services, replica sets, pods, and containers illustrated. The diagram visualizes how a new version is gradually introduced." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/canary-release-kubernetes-ingress-90-10.jpg" />
</Frame>

You can adjust the routed percentage (for example 90/10, 95/5, etc.), but the defining trait of canary is the gradual traffic split.

Blue–green releases, by contrast, switch all user traffic from v1 to v2 in a single cutover. There is no gradual ramp — users are on v1 one moment and v2 the next.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/blue-green-kubernetes-ingress-v1-v2.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=3efd2613712c2a4bdc63d56f9d8f07fc" alt="A diagram titled &#x22;Blue/Green Release&#x22; showing a Kubernetes namespace where an Ingress Gateway routes user traffic to a Service, which forwards to two deployments (V1 and V2) with replica sets and multiple pods/containers." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/blue-green-kubernetes-ingress-v1-v2.jpg" />
</Frame>

Both approaches have trade-offs. Use the table below to compare them quickly.

| Strategy   | Rollout pattern                      | Risk exposure                                   | Best for                                         |
| ---------- | ------------------------------------ | ----------------------------------------------- | ------------------------------------------------ |
| Canary     | Gradual traffic ramp (percent-based) | Low exposure early; increases as ramp proceeds  | Safely validate behavior with a subset of users  |
| Blue–Green | All-or-nothing cutover               | Full exposure at switch; fast rollback possible | Quick, atomic switch when environments are ready |

Ideally you want the low-risk validation of a canary with the ability to test the new version against full production traffic. Istio’s traffic mirroring helps you achieve that combination.

## What is Istio traffic mirroring?

Istio traffic mirroring sends a copy of live production requests to another version of your service (for example, a staging or test instance) while the original response still goes to production. Mirroring lets you exercise v2 with real requests and production payloads without affecting user-visible responses.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/k8s-traffic-mirroring-ingress-service-deployments.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=7bb46ad3a2c7958acf5f0e64ee866410" alt="Diagram of traffic mirroring in Kubernetes: users send requests via an Ingress Gateway to a Service inside a Namespace. The Service routes traffic to two deployments (V1 and V2) showing replica sets, pods and containers." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/k8s-traffic-mirroring-ingress-service-deployments.jpg" />
</Frame>

Key points:

* Mirrored requests are copies — responses from the mirrored destination are ignored by Istio and never returned to the client.
* Mirroring is asynchronous and safe for exercising read-only behavior and performance testing.
* Avoid side effects (for example, writes to production databases) from mirrored requests unless you have safeguards (see the warning below).

<Callout icon="warning" color="#FF6B6B">
  Mirrored traffic still reaches the mirrored service. If that service performs writes (to databases, external APIs, or modifies shared state), those side-effects will occur unless explicitly isolated. Always ensure mirrored requests are safe or routed to an isolated environment to avoid corrupting production data.
</Callout>

## Deployments and Service setup

To enable mirroring you need two versions of your application deployed — for example `v1` (production) and `v2` (mirror/test). Both deployments can share the same Service selector (e.g., `app: frontend`) so that Istio can route to subsets defined by a DestinationRule.

Example Kubernetes Deployment and Service manifests:

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-v2-deployment
  namespace: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: frontend
      version: v2
  template:
    metadata:
      labels:
        app: frontend
        version: v2
    spec:
      containers:
      - name: app
        image: app:2.1
---
apiVersion: v1
kind: Service
metadata:
  name: app-svc
  namespace: frontend
spec:
  ports:
  - port: 80
    name: http
  selector:
    app: frontend
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-v1-deployment
  namespace: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: frontend
      version: v1
  template:
    metadata:
      labels:
        app: frontend
        version: v1
    spec:
      containers:
      - name: app
        image: app:1.1
```

Note:

* The Service `app-svc` selects pods with `app: frontend`. Subsets (v1, v2) are distinguished by the `version` label and defined in a DestinationRule.

## VirtualService and DestinationRule for mirroring

Mirroring is configured in an Istio VirtualService by adding a `mirror` destination to the primary `route`. The mirrored subset(s) are declared in a matching DestinationRule.

Example VirtualService and DestinationRule that implement mirroring:

```yaml theme={null}
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: app-vs
  namespace: frontend
spec:
  hosts:
  - app-svc
  http:
  - route:
    - destination:
        host: app-svc
        port:
          number: 80
        subset: v1
      weight: 100
    mirror:
      host: app-svc
      port:
        number: 80
      subset: v2
    mirrorPercent: 100
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: app-ds
  namespace: frontend
spec:
  host: app-svc
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
```

In this setup:

* The `route` section sends all user-facing requests to subset `v1`.
* The `mirror` section sends a copy of each request to subset `v2`.
* `mirrorPercent` controls the fraction of requests that are mirrored (0–100). Use lower values to sample mirrored traffic.

<Callout icon="lightbulb" color="#1CB2FE">
  Mirrored requests are sent asynchronously to the mirror destination; responses from the mirrored service are ignored by Istio and not returned to the user. Mirroring is therefore safe for exercising behavior but should not be used for anything that affects observable user state (e.g., writing to production databases) unless you take appropriate safeguards.
</Callout>

## Why use mirroring?

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/mirroring-benefits-testing-production-zero-impact.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=c3c60682bbe8af65c86ae15d89c36219" alt="A presentation slide titled &#x22;Why Use Mirroring?&#x22; with a vertical, color-coded list of five benefits. Each numbered item (with small icons) mentions testing new service versions in production, identifying issues early, zero impact on users, safe switching after validation, and gaining performance/debugging insights." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/mirroring-benefits-testing-production-zero-impact.jpg" />
</Frame>

Mirroring provides several practical benefits:

* Validate new service versions with real production traffic without impacting users.
* Discover issues earlier using live workloads and production payloads.
* Maintain zero user impact because mirrored responses are discarded.
* Confidently verify v2 behavior before a full cutover or canary ramp.
* Collect realistic performance metrics and debugging traces under production load.

## Mirroring configuration options

Istio supports a few mirroring options you should know about:

* `mirror` destination: specifies host/port/subset to receive mirrored requests.
* `mirrorPercent`: sample rate for mirrored traffic (0–100).
* `PortSelector`: explicitly choose a target port for mirrored traffic.
* `HTTPMirrorPolicy` fields available on the VirtualService HTTP route.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/mirroring-options-httpmirrorpolicy-portselector-percent.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=57847cedc012eb03efbdee19ef1ab051" alt="A documentation-style slide titled &#x22;Mirroring Options&#x22; showing HTTPMirrorPolicy, PortSelector and Percent sections with tables and a right-hand HTTPRoute reference panel. It includes a KodeKloud copyright and a link to the istio.io docs." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Mirroring/mirroring-options-httpmirrorpolicy-portselector-percent.jpg" />
</Frame>

For the most up-to-date API and fields, see the Istio VirtualService documentation:

* Istio VirtualService reference: [https://istio.io/latest/docs/reference/config/networking/virtual-service/](https://istio.io/latest/docs/reference/config/networking/virtual-service/)

## Quick checklist to enable mirroring

1. Deploy production version (v1) and the mirrored/test version (v2).
2. Ensure both deployments share the Service selector (for example `app: frontend`).
3. Create a DestinationRule with `subsets` matching the `version` labels.
4. Create or update the VirtualService: route primary traffic to `v1`, set `mirror` to `v2`, and adjust `mirrorPercent`.
5. Monitor mirrored service logs, traces, and metrics to validate behavior.
6. Gradually increase `mirrorPercent` if you need more sampling before a full rollout.

## Best practices

* Use mirroring for read-only validation, performance testing, and debugging.
* Isolate mirrored environments from production stateful systems (databases, billing systems) to prevent accidental writes.
* Start with a small `mirrorPercent` (for example 1–5%) when traffic volume is high to limit load.
* Combine mirroring with tracing and logging so you can correlate production and mirrored requests.
* Clean up or scale down mirrored deployments when validation is complete.

References

* Istio VirtualService docs: [https://istio.io/latest/docs/reference/config/networking/virtual-service/](https://istio.io/latest/docs/reference/config/networking/virtual-service/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/istio-certified-associate/module/f3f5ca4b-b8d6-4788-9553-9ed765709933/lesson/40d8a24b-c16f-4781-9c26-20d4b1d5baf3" />
</CardGroup>
