[HTTP method matching] Request method matching
HTTP rules select how to handle an incoming request based on the request method (such as GET and POST).
Prerequisites
You have completed the Preparations and deployed the helloworld service and the sleep service.
Procedure
-
Verify that the service configuration takes effect.
-
In the KubeConfig environment of the Container Service for Kubernetes (ACK) cluster, enter the sleep environment and start a shell.
kubectl exec -it deploy/sleep -- sh -
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 at random:
Hello version: v2, instance: helloworld-v2-6b96c5684-4**** Hello version: v1, instance: helloworld-v1-6d77f4c4cf-p****
-
-
Use the following content to configure the 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 -
Use the following content to create a virtual service and add the HTTP Method Matching configuration (GET requests are handled by helloworld-v1). For instructions, see Manage virtual services.
apiVersion: networking.istio.io/v1beta1 kind: VirtualService metadata: name: helloworld-vs namespace: default spec: hosts: - helloworld http: - match: - method: exact: GET route: - destination: host: helloworld subset: v1 -
Verify that the configuration takes effect.
-
In the KubeConfig environment of the ACK cluster, enter the sleep environment and start a shell.
kubectl exec -it deploy/sleep -- sh -
Send a GET request to the helloworld service.
curl -X GET helloworld:5000/helloThe expected output is always the following result, which helloworld-v1 returns:
Hello version: v1, instance: helloworld-v1-6986f64596-s****
-