Set up Istio’s Components for Traffic Management

A central advantage of traffic management in Istio is that it allows dynamic request routing. Some common applications for dynamic request routing include canary deployments and blue/green deployments. The two key resources in Istio traffic management are virtual services and destination rules.

  • Virtual services intercept and direct traffic to your Kubernetes services, allowing you to divide percentages of traffic from a request to different services. You can use them to define a set of routing rules to apply when a host is addressed.
  • Destination rules serve as the single source of truth about which service versions are available to receive traffic from virtual services. You can use these resources to define policies that apply to traffic that is intended for a service after routing has occurred.

This section describes how to add an example virtual service that corresponds to the reviews microservice in the sample BookInfo app. The purpose of this service is to divide traffic between two versions of the reviews service.

In this example, we take the traffic to the reviews service and intercept it so that 50 percent of it goes to v1 of the service and 50 percent goes to v2.

After this virtual service is deployed, we will generate traffic and see from the Kiali visualization that traffic is being routed evenly between the two versions of the service.

To deploy the virtual service and destination rules for the reviews service,

  1. Click ☰ > Cluster Management.

  2. Go to the cluster where Istio is installed and click Explore.

  3. In the cluster where Istio is installed, click Istio > DestinationRules in the left navigation bar.

  4. Click Create.

  5. Copy and paste the DestinationRule yaml provided below.

  6. Click Create.

  7. Click Edit as YAML and use this configuration:

    1. apiVersion: networking.istio.io/v1alpha3
    2. kind: DestinationRule
    3. metadata:
    4. name: reviews
    5. spec:
    6. host: reviews
    7. subsets:
    8. - name: v1
    9. labels:
    10. version: v1
    11. - name: v2
    12. labels:
    13. version: v2
    14. - name: v3
    15. labels:
    16. version: v3
  8. Click Create.

Then to deploy the VirtualService that provides the traffic routing that utilizes the DestinationRule:

  1. Click VirtualService in the side nav bar.
  2. Click Create from Yaml.
  3. Copy and paste the VirtualService yaml provided below.
  4. Click Create.
  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: reviews
  5. spec:
  6. hosts:
  7. - reviews
  8. http:
  9. - route:
  10. - destination:
  11. host: reviews
  12. subset: v1
  13. weight: 50
  14. - destination:
  15. host: reviews
  16. subset: v3
  17. weight: 50
  18. ---

Result: When you generate traffic to this service (for example, by refreshing the ingress gateway URL), the Kiali traffic graph will reflect that traffic to the reviews service is divided evenly between v1 and v3.

Next: Generate and View Traffic