Host

Expose a route on multiple hosts.

For more information, see the Kubernetes Gateway API documentation.

Before you begin

  1. Set up an agentgateway proxy.
  2. Install the httpbin sample app.

Set up host matching

  1. Create an HTTPRoute that is exposed on two domains, host1.example and host2.example.

    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:
        - host1.example
        - host2.example
      rules:
        - backendRefs:
            - name: httpbin
              port: 8000
    EOF
  2. Send a request to the /status/200 path of the httpbin app on the host1.example domain. Verify that you get back a 200 HTTP response code.

    curl -vi http://$INGRESS_GW_ADDRESS:80/status/200 -H "host: host1.example"
    curl -vi localhost:8080/status/200 -H "host: host1.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
  3. Send another request to the httpbin app. This time, you send it along the host2.example domain. Verify that the request succeeds and that you also get back a 200 HTTP response code.

    curl -vi http://$INGRESS_GW_ADDRESS:80/status/200 -H "host: host2.example"
    curl -vi localhost:8080/status/200 -H "host: host2.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