# Istio - Mirroring

https://istio.io/docs/tasks/traffic-management/mirroring/ (opens new window)

Mirroring sends a copy of live traffic to a mirrored service.

First all traffic will go to reviews:v1, then the rule will be applied to mirror a portion of traffic to reviews:v2.

Apply the virtual services which will route all traffic to reviews:v1 of each microservice:

kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml

Change the route rule to mirror traffic to reviews:v2:

cat << EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
  name: reviews
    - reviews
  - route:
    - destination:
        host: reviews
        subset: v1
      weight: 100
      host: reviews
      subset: v2

Check the logs on both pods reviews:v1 and reviews:v2 by splitting the byobu screen and checking logs of the pod:

# Use "Ctrl + Alt then TAB" to switch between screens
byobu-tmux split-window -v
# Screen 1
kubectl logs $(kubectl get pod -l app=reviews,version=v1 -o jsonpath="{.items[0].metadata.name}") istio-proxy -f
# Screen 2
kubectl logs $(kubectl get pod -l app=reviews,version=v2 -o jsonpath="{.items[0].metadata.name}") istio-proxy -f

Do a simple query by refreshing the page in the web browser.


# Request comming to: reviews,version=v1
[2019-02-21T09:50:40.978Z] "GET /reviews/0HTTP/1.1" 200 - 0 295 3 2 "-" "python-requests/2.18.4" "fadff2a1-e895-4ff2-a6c6-17c0334a339d" "reviews:9080" "" inbound|9080||reviews.default.svc.cluster.local -

# Request comming to: reviews,version=v2
[2019-02-21T09:50:40.988Z] "GET /ratings/0HTTP/1.1" 200 - 0 48 4 3 "-" "Apache-CXF/3.1.14" "fadff2a1-e895-4ff2-a6c6-17c0334a339d" "ratings:9080" "" outbound|9080|v1|ratings.default.svc.cluster.local -
[2019-02-21T09:50:40.977Z] "GET /reviews/0HTTP/1.1" 200 - 0 379 18 16 "" "python-requests/2.18.4" "fadff2a1-e895-4ff2-a6c6-17c0334a339d" "reviews-shadow:9080" "" inbound|9080||reviews.default.svc.cluster.local -

Check the flows in Kiali graph

Mirroring Kiali Graph