Right now, every request goes to v1 The web app calls the api Service. As in the previous lesson, both pods have sidecars, and requests pass the web-side proxy to reach api v1.
In a service mesh, the proxy on the sending side picks the destination. So split rules apply at this proxy.
Deploy v2 with no rules and traffic splits by pod count Start new pods labeled version: v2 behind the same api Service. The Service groups pods by label, so it does not tell v1 from v2.
Without split rules, the proxy spreads requests evenly across the pods behind the Service. With one pod each, about half the requests go to the untested v2.
A DestinationRule names each version In a DestinationRule (rules for the destination side), write "pods with version: v1 are subset v1, pods with version: v2 are subset v2". Write it in YAML and create it with kubectl apply.
This only names them, so traffic flow does not change yet. Run kubectl get destinationrule -o yaml to check that subsets contains v1 and v2.
Key idea Without subsets, a VirtualService has no way to point at v1 and v2 separately.
A VirtualService sets v1 to 90% and v2 to 10% In a VirtualService (rules for where requests go and in what share), write "90% of requests to api go to subset v1, 10% to subset v2". istiod pushes this rule to the web-side proxy.
The proxy picks a destination for each request by these weights. Sending a small share to the new version first is called a canary release.
Key idea Weights do not depend on pod count. Even with a single v2 pod, it gets exactly the 10% you set.
Send only requests with a given header to v2 You can add a condition checked before the weights. For example, requests with a tester header (a value like end-user: qa) always go to v2, and the rest follow 90 : 10.
VirtualService rules are matched top to bottom, and the first match wins. So put narrow conditions (headers) on top and broad ones (weights) below.
Key idea The app must pass the header along on its next calls. If a service in the middle drops the header, the condition stops matching after that point.
The DestinationRule sets rules for after arrival Besides subsets, the DestinationRule handles destination-side rules. The load balancing method for picking pods within a subset and TLS settings go here.
Caps on connections and pending requests (connection limits), and a rule that temporarily removes pods that keep failing (circuit breaker), also go in the DestinationRule. They keep a surge of requests from knocking over one version.
Key idea If circuit breaker thresholds are too sensitive, healthy pods get removed too.
Retries and timeouts go in the VirtualService v2 has slowed down. Put "how many times to resend on failure (retries)" and "how long to wait before giving up (timeout)" in the VirtualService, and the proxy handles them for you.
Retries are not free. On requests that must not run twice, such as payments, they cause duplicate processing. Retrying at several points in a call chain multiplies the load on a slow service.
Watch out As a rule, retry at only one point in the chain, with growing intervals. If an upstream timeout is shorter than the downstream one, the upstream gives up before the downstream finishes.
If v2 has problems, roll back the weights Errors are rising on v2. Open the VirtualService with kubectl edit virtualservice and change the weights to 100 : 0.
You do not delete or redeploy pods. Once the new rule reaches the proxy, all new requests go to v1, and you keep the v2 pods to investigate.
Watch out A rolling update rollback swaps pods again, but a mesh rollback only changes the weight numbers.
DestinationRule is "what"; VirtualService is "where and how much" The DestinationRule defines version groups (subsets) and connection rules after arrival. The VirtualService defines weights, header conditions, retries, and timeouts. The sending-side proxy does the actual splitting.
Tools such as Argo Rollouts and Flagger raise these weights step by step based on metrics, and roll back when they see problems.
Summary The DestinationRule sets version groups and post-arrival connection rules. The VirtualService sets where and what %, retries, and timeouts. Weight changes affect traffic immediately, so manage them in Git and check metrics after each change.