All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure query parameter matching

Last Updated:Oct 16, 2023

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

  1. Check whether the service configurations take effect.

    1. Use kubectl to connect to the Container Service for Kubernetes (ACK) cluster based on the information in the kubeconfig file, and run the following command to enable bash for the sleep service:

      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 that helloworld-v1 or helloworld-v2 randomly responds to the request.

      Hello version: v2, instance: helloworld-v2-7d48f6b995-6****
      Hello version: v1, instance: helloworld-v1-6986f64596-s****
  2. Use the istioctl tool to run the following commands to deploy a Layer 7 waypoint proxy for the helloworld service:

    istioctl x waypoint apply --service-account helloworld-v1
    istioctl x waypoint apply --service-account helloworld-v2
  3. Use the following content to create 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
    
  4. Use the following content to create a virtual service and add a header matching configuration. For more information, see Manage virtual services.

    The following configuration indicates that requests with test-params set to v1 are sent to helloworld-v1 and requests with test-params set to v2 are sent to helloworld-v2.

    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. Check whether the query parameter matching configuration takes effect.

    1. Use kubectl to connect to the ACK cluster based on the information in the kubeconfig file, and run the following command to enable bash for the sleep service:

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request with test-params=v1 to the helloworld service:

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

      Expected output:

      Hello version: v1, instance: helloworld-v1-6986f64596-s****
    3. Run the following command to send a request with test-params=v2 to the helloworld service:

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

      Expected output:

      Hello version: v2, instance: helloworld-v2-7d48f6b995-6****

      The preceding results indicate that the query parameter matching configuration takes effect.