URI Path Matching
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
Verify that the service configuration takes effect.
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 -- shRun the following command to send a request to the helloworld service.
curl helloworld:5000/helloThe 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****
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: v2Use the following content to create a virtual service and add the URI Path Matching configuration. For instructions, see Manage virtual services.
Verify that the configuration takes effect.
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 -- shRun the following command to send a request to the
/hellopath of the helloworld service.curl helloworld:5000/helloThe expected output is always the following result, because helloworld-v1 responds.
Hello version: v1, instance: helloworld-v1-6d77f4c4cf-p****
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