For more information, see the Kubernetes Gateway API documentation.

Before you begin

  1. Follow the Get started guide to install Gloo Gateway, set up a gateway resource, and deploy the httpbin sample app.

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

Set up header matching

  1. Create an HTTPRoute resource.

      kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1beta1
    kind: HTTPRoute
    metadata:
      name: httpbin-match
      namespace: httpbin
    spec:
      parentRefs:
        - name: http
          namespace: gloo-system
      hostnames:
        - match.example
      rules:
        - matches:
          - headers:
            - name: version
              value: v2
              type: Exact
          backendRefs:
            - name: httpbin
              port: 8000
    EOF 
      
  2. Send a request to the httpbin app on the match.example domain withouth any headers. Verify that you get back a 404 HTTP response code as no matching request could be 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:16:43 GMT
    date: Sat, 04 Nov 2023 03:16:43 GMT
    < server: envoy
    server: envoy
    < content-length: 0
    content-length: 0
      
  3. Send another request to the httpbin app on the match.example domain. This time, add the version: v2 header that you configured in the HTTP route. Verify that your request now succeeds and 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:19:26 GMT
    date: Sat, 04 Nov 2023 03:19:26 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