Query parameter matching
When you send a request, you can include query parameters that are used for matching. This topic describes how to configure query parameter matching.
Prerequisites
You have completed the preparations and deployed the helloworld service and the sleep service. For more information, see Preparations.
Procedure
Verify whether 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: v1, instance: helloworld-v1-6d77f4c4cf-p**** Hello version: v2, instance: helloworld-v2-6b96c5684-4****
Use the following content to configure a destination rule. For more information, 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 Query Parameter Matching configuration. For more information, see Manage virtual services.
The following configuration indicates that request traffic whose
test-paramsis set tov1is sent to helloworld-v1, and request traffic whosetest-paramsis set tov2is sent to helloworld-v2.Verify whether 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 with the
test-params=v1parameter to the helloworld service.curl helloworld:5000/hello?test-params=v1Expected output:
Hello version: v1, instance: helloworld-v1-6d77f4c4cf-p****Run the following command to send a request with the
test-params=v2parameter to the helloworld service.curl helloworld:5000/hello?test-params=v2Expected output:
Hello version: v2, instance: helloworld-v2-6b96c5684-4****
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: helloworld-vs
namespace: default
spec:
hosts:
- helloworld
http:
- match:
- queryParams:
test-params:
exact: v1
route:
- destination:
host: helloworld
subset: v1
- match:
- queryParams:
test-params:
exact: v2
route:
- destination:
host: helloworld
subset: v2