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
Get the external address of the gateway and save it in an environment variable.
Set up query parameter matching
Create an HTTPRoute resource for the
match.exampledomain that matches incoming requests with auser=mequery parameter.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-match namespace: httpbin spec: parentRefs: - name: http namespace: gloo-system hostnames: - match.example rules: - matches: - queryParams: - type: Exact value: me name: user backendRefs: - name: httpbin port: 8000 EOFSend a request to the
/status/200path of the httpbin app on thematch.exampledomain without any query parameters. Verify that your request is not forwarded to the httpbin app because no matching query parameter is found.Example output:
* Mark bundle as not supporting multiuse < HTTP/1.1 404 Not Found HTTP/1.1 404 Not Found < date: Sat, 04 Nov 2023 03:45:39 GMT date: Sat, 04 Nov 2023 03:45:39 GMT < server: envoy server: envoy < content-length: 0 content-length: 0Send a request to the
/status/200path of the httpbin app on thematch.exampledomain. This time, you provide theuser=mequery parameter. Verify that your request now succeeds and that you get back a 200 HTTP response code.Example output:
* Mark bundle as not supporting multiuse < 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: * < date: Sat, 04 Nov 2023 03:49:17 GMT date: Sat, 04 Nov 2023 03:49:17 GMT < content-length: 0 content-length: 0 < x-envoy-upstream-service-time: 1 x-envoy-upstream-service-time: 1 < server: envoy server: envoy
Cleanup
You can optionally delete the HTTP route that you created as part of this guide.
kubectl delete httproute httpbin-match -n httpbin