Learn to adjust traffic distribution and implement header-based routing for application versions using Destination Rules and Virtual Services.
In this lesson, you will learn how to adjust traffic weight distribution between different versions of the reviews application and implement header-based routing rules. This guide details how to define application versions with Destination Rules, create a Virtual Service to manage traffic distribution, and apply advanced routing policies based on request headers.──────────────────────────────
Before modifying traffic distribution, you must define the different versions of your application using Destination Rules. Apply the default Destination Rules from the Samples directory with the following command:
destinationrule.networking.istio.io/productpage createddestinationrule.networking.istio.io/reviews createddestinationrule.networking.istio.io/ratings createddestinationrule.networking.istio.io/details created
Destination Rules allow Istio to control traffic policies for different versions (or subsets) of an application.
2. Create a Virtual Service with Traffic Weight Distribution
Create a Virtual Service for the reviews application to split traffic between two subsets (v1 and v2) with a 75-25% distribution. Ensure that the total weight equals 100.The YAML configuration below sets up the Virtual Service:
Apply the Virtual Service and verify its configuration with the commands below:
Copy
Ask AI
kubectl apply -f samples/bookinfo/networking/destination-rule-all.yamlvi virtual-service1.yaml # Edit the file if necessarykubectl apply -f virtual-service1.yamlistioctl analyze
You should see output similar to:
Copy
Ask AI
destinationrule.networking.istio.io/productpage createddestinationrule.networking.istio.io/reviews createddestinationrule.networking.istio.io/ratings createddestinationrule.networking.istio.io/details createdvirtualservice.networking.istio.io/reviews created✓ No validation issues found when analyzing namespace: default.
Switch to Kiali to inspect your Istio configurations. In Kiali, you will see that the Destination Rule for the reviews service defines three subsets (v1, v2, and v3):
When you access the reviews application, version v1 should be more frequent than version v2, reflecting the 75-25 traffic split. This difference becomes more apparent as traffic increases.
In addition to traffic splitting, Virtual Services allow you to create advanced routing policies based on request headers. This feature is particularly useful if you want to serve different application versions based on user attributes.
When a KodeKloud user signs in, the “end-user” header is set to “kodekloud”, and the user sees the version v2 experience (represented with a black star).
Requests with “end-user: kodekloud” are routed to version v2.
Requests with “end-user: testuser” go to the new version v3.
All other requests default to version v1.
When users sign in with their respective usernames, these routing rules take effect without interfering with the predefined traffic weights.──────────────────────────────
Virtual Services empower you to control and manage traffic flow between different application versions seamlessly. In this lesson, you learned how to:
Define application versions using Destination Rules.
Configure weight-based traffic splitting through a Virtual Service.
Validate the configuration with Istio analysis tools and Kiali.
Implement header-based routing to tailor the user experience based on request attributes.
These strategies enable safe feature rollouts, A/B testing, and dynamic production traffic management.For more detailed information, refer to the following resources: