Query parameter

Specify a set of URL query parameters which requests must match in entirety.

For more information, see the Kubernetes Gateway API documentation.

Before you begin

  1. Follow the Get started guide to install kgateway.

  2. Follow the Sample app guide to create a gateway proxy with an HTTP listener and deploy the httpbin sample app.

  3. Get the external address of the gateway and save it in an environment variable.

    export INGRESS_GW_ADDRESS=$(kubectl get svc -n agentgateway-system http -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}")
    echo $INGRESS_GW_ADDRESS  
    kubectl port-forward deployment/http -n agentgateway-system 8080:8080

Set up query parameter matching

  1. Create an HTTPRoute resource for the match.example domain that matches incoming requests with a user=me query parameter.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: httpbin-match
      namespace: httpbin
    spec:
      parentRefs:
        - name: agentgateway-proxy
          namespace: agentgateway-system
      hostnames:
        - match.example
      rules:
        - matches:
          - queryParams: 
              - type: Exact
                value: me
                name: user
          backendRefs:
            - name: httpbin
              port: 8000
    EOF
  2. Send a request to the /status/200 path of the httpbin app on the match.example domain without any query parameters. Verify that your request is not forwarded to the httpbin app because no matching query parameter is found.

    curl -vi http://$INGRESS_GW_ADDRESS:80/status/200 -H "host: match.example"
    curl -vi localhost:8080/status/200 -H "host: match.example"

    Example output:

    < HTTP/1.1 404 Not Found
    HTTP/1.1 404 Not Found
    < content-length: 9
    content-length: 9
    < content-type: text/plain; charset=utf-8
    content-type: text/plain; charset=utf-8
  3. Send a request to the /status/200 path of the httpbin app on the match.example domain. This time, you provide the user=me query parameter. Verify that your request now succeeds and that you get back a 200 HTTP response code.

    curl -vi "http://$INGRESS_GW_ADDRESS:80/status/200?user=me" -H "host: match.example"
    curl -vi "localhost:8080/status/200?user=me" -H "host: match.example"

    Example output:

    * Request completely sent off
    < HTTP/1.1 200 OK
    HTTP/1.1 200 OK
    < access-control-allow-credentials: true
    access-control-allow-credentials: true
    < access-control-allow-origin: *
    access-control-allow-origin: *
    < content-length: 0
    content-length: 0

Cleanup

You can remove the resources that you created in this guide.
kubectl delete httproute httpbin-match -n httpbin