Activity: Canary Rollout of discounts service

Module 2

To enable canary rollout, you will run a simple script to gradually shift traffic from v1 to v2 in stages: 10%, 25%, 50%, 75%, and finally 100%. The script patches the VirtualService on the fly, and you’ll observe the results in real time via Kiali and from logs in the terminal.

This script is meant for illustrative and educational purposes. In a real-world production environment, organizations typically use a progressive delivery tool like Argo Rollouts which is included as part of OpenShift.

  1. In the upper terminal, run this log monitoring script which trails the logs of v1 and v2 discounts pods.

    sh <(curl -s https://raw.githubusercontent.com/app-connectivity-workshop/scripts/refs/heads/main/m2/canary-monitoring.sh)

    You should immediately start seeing log output from discounts-v1 [discounts/v1].

    log output pre rollout

  2. In the lower terminal, run the following canary-rollout script. This script shifts traffic from v1 to v2 by updating the VirtualService you created earlier,

    sh <(curl -s https://raw.githubusercontent.com/app-connectivity-workshop/scripts/refs/heads/main/m2/canary-rollout.sh)

    This will start updating the weights in the VirtualService every 20 seconds.

    log output 50 50 rollout

  3. Once the rollout begins, you will see logs in the upper terminal for discount-v2 [discount/v2] gradually increase, while log messages from discount-v1 [discount/v1] decrease.

  4. As the script progresses, you can also visualise the deployment of the Kiali console. Navigate to the Kiali console using this link to make sure you have the right display options set in the Kiali Traffic Graph

  5. You will begin by seeing all traffic being routed to v1. Click image to zoom in.

    canary k 0

  6. Although Kiali will lag by 1 minute, you’ll begin to see more and more requests routed to the discounts-v2 pod as the script progresses. Click image to zoom in.

    canary k 1

  7. And finally, all traffic is routed to v2. Click image to zoom in.

    canary k 2

  8. Expected final output in the lower terminal

    Begin Canary Rollout...
    100% traffic routed to v1, 0% to v2
    virtualservice.networking.istio.io/discounts patched
    90% traffic routed to v1, 10% to v2
    virtualservice.networking.istio.io/discounts patched
    75% traffic routed to v1, 25% to v2
    virtualservice.networking.istio.io/discounts patched
    50% traffic routed to v1, 50% to v2
    virtualservice.networking.istio.io/discounts patched
    25% traffic routed to v1, 75% to v2
    virtualservice.networking.istio.io/discounts patched
    0% traffic routed to v1, 100% to v2
  9. Press Ctrl+C to stop the log output in the upper terminal.

Congratulations! You’ve just performed a progressive rollout of a new version of a microservice using weighted routing in OpenShift Service Mesh.

Optional Activity: Reset traffic to v1

Run the following command on the lower terminal to reset traffic to discounts service v1

oc -n travel-agency patch virtualservice discounts --type=json -p='[
  {"op": "replace", "path": "/spec/http/0/route/0/weight", "value": 100},
  {"op": "replace", "path": "/spec/http/0/route/1/weight", "value": 0}
]'