A request can carry query parameters for matching. This topic describes how to configure query parameter matching.
Prerequisites
The preparations are completed, and the helloworld and sleep services are deployed. For more information, see Preparations.
Procedure
Check whether the service configurations take effect.
Use kubectl to connect to the Container Service for Kubernetes (ACK) cluster based on the information in the kubeconfig file, and then run the following command to enable bash for the sleep service:
kubectl exec -it deploy/sleep -- shRun the following command to send a request to the helloworld service:
curl helloworld:5000/helloThe expected output is that helloworld-v1 or helloworld-v2 randomly responds to the request.
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 a query parameter matching configuration. For more information, see Manage virtual services.
The following configuration indicates that requests with
test-paramsset tov1are sent to helloworld-v1 and requests withtest-paramsset tov2are sent to helloworld-v2.Check whether the configurations take effect.
Use kubectl to connect to the ACK cluster based on the information in the kubeconfig file, and then run the following command to enable bash for the sleep service:
kubectl exec -it deploy/sleep -- shRun the following command to send a request with
test-params=v1to 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
test-params=v2to 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