URI Path Matching

Updated at:

For incoming requests, HTTP rules determine how each request is handled based on the request URI. A virtual service supports exact match, prefix match, and regular expression match rules for URI paths. This topic describes how to configure URI path matching.

Prerequisites

The preparations are complete, and the helloworld service and the sleep service are deployed. For instructions, see Preparations.

Procedure

  1. Verify that the service configuration takes effect.

    1. In the KubeConfig environment of the ACK cluster, run the following command to enter the sleep environment and start bash.

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request to the helloworld service.

      curl helloworld:5000/hello

      The expected output is one of the following two results, because helloworld-v1 and helloworld-v2 respond randomly.

      Hello version: v2, instance: helloworld-v2-6b96c5684-4****
      Hello version: v1, instance: helloworld-v1-6d77f4c4cf-p****
  2. Use the following content to configure a destination rule. For instructions, see Manage destination rules.

    apiVersion: networking.istio.io/v1beta1
    kind: DestinationRule
    metadata:
      name: helloworld
      namespace: default
    spec:
      host: helloworld
      subsets:
        - labels:
            version: v1
          name: v1
        - labels:
            version: v2
          name: v2
    
  3. Use the following content to create a virtual service and add the URI Path Matching configuration. For instructions, see Manage virtual services.

  4. apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: helloworld-vs
      namespace: default
    spec:
      hosts:
        - helloworld
      http:
        - match:
            - uri:
                exact: /hello
          route:
            - destination:
                host: helloworld
                subset: v1
  5. Verify that the configuration takes effect.

    1. In the KubeConfig environment of the ACK cluster, run the following command to enter the sleep environment and start bash.

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request to the /hello path of the helloworld service.

      curl helloworld:5000/hello

      The expected output is always the following result, because helloworld-v1 responds.

      Hello version: v1, instance: helloworld-v1-6d77f4c4cf-p****