Query parameter matching

Updated at:

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

  1. Verify whether 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: v1, instance: helloworld-v1-6d77f4c4cf-p****
      Hello version: v2, instance: helloworld-v2-6b96c5684-4****
  2. 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: v2
    
  3. Use 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-params is set to v1 is sent to helloworld-v1, and request traffic whose test-params is set to v2 is sent to helloworld-v2.

  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
    
  5. Verify whether 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 with the test-params=v1 parameter to the helloworld service.

      curl helloworld:5000/hello?test-params=v1

      Expected output:

      Hello version: v1, instance: helloworld-v1-6d77f4c4cf-p****
    3. Run the following command to send a request with the test-params=v2 parameter to the helloworld service.

      curl helloworld:5000/hello?test-params=v2

      Expected output:

      Hello version: v2, instance: helloworld-v2-6b96c5684-4****