Skip to content

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Page as Markdown

Multi-level delegation

Create a 3-level route delegation hierarchy with a parent, child, and grandchild HTTPRoute.

Verified Code examples on this page have been automatically tested and verified.

Create a 3-level route delegation hierarchy with a parent, child, and grandchild HTTPRoute.

Configuration overview

In this guide, you set up a 3-level route delegation hierarchy. The parent HTTPRoute delegates to a child, and the child delegates to a grandchild that forwards traffic to an httpbin sample app.

The following image illustrates the route delegation hierarchy:

parent HTTPRoute:

  • Delegates traffic as follows:
    • /anything/team1 is delegated to the child HTTPRoute child-team1 in namespace team1.
    • /anything/team2 is delegated to the child HTTPRoute child-team2 in namespace team2.

child-team1 HTTPRoute:

  • Matches incoming traffic for the /anything/team1/foo prefix path and routes that traffic to the httpbin app in the team1 namespace.

child-team2 HTTPRoute:

  • Delegates traffic on the /anything/team2/grandchild/ prefix to a grandchild HTTPRoute in the team2 namespace.

grandchild HTTPRoute:

  • Matches incoming traffic for the /anything/team2/grandchild/.* regex path and routes that traffic to the httpbin app in the team2 namespace.

Before you begin

  1. Follow the Get started guide to install agentgateway.

  2. Follow the Sample app guide to create the agentgateway-proxy Gateway with an HTTP listener.

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

    export INGRESS_GW_ADDRESS=$(kubectl get svc -n agentgateway-system agentgateway-proxy -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}")
    echo $INGRESS_GW_ADDRESS

  4. Create the namespaces for team1 and team2.

    kubectl create namespace team1
    kubectl create namespace team2
  5. Deploy the httpbin app into both namespaces. The httpbin app exposes endpoints such as /anything/..., /headers, and /delay/N that are useful for verifying routing and policy behavior.

    curl -sL https://raw.githubusercontent.com/kgateway-dev/kgateway/main/examples/httpbin.yaml \
      | awk 'BEGIN{skip=0} /^kind: Namespace$/{skip=1} skip==0{print} /^---$/{skip=0}' \
      | sed 's/namespace: httpbin/namespace: team1/g' \
      | kubectl apply -f -
    
    curl -sL https://raw.githubusercontent.com/kgateway-dev/kgateway/main/examples/httpbin.yaml \
      | awk 'BEGIN{skip=0} /^kind: Namespace$/{skip=1} skip==0{print} /^---$/{skip=0}' \
      | sed 's/namespace: httpbin/namespace: team2/g' \
      | kubectl apply -f -
  6. Verify that the httpbin apps are up and running.

    kubectl get pods -n team1
    kubectl get pods -n team2

    Example output:

    NAME                       READY   STATUS    RESTARTS   AGE
    httpbin-6bc5b79755-xlvjf   3/3     Running   0          7s
    NAME                       READY   STATUS    RESTARTS   AGE
    httpbin-6bc5b79755-twxq9   3/3     Running   0          6s

Setup

  1. Create the parent HTTPRoute that matches incoming traffic on the delegation.example domain. The HTTPRoute specifies two routes:

    • /anything/team1: The routing decision is delegated to a child HTTPRoute in the team1 namespace.
    • /anything/team2: The routing decision is delegated to a child HTTPRoute in the team2 namespace.
    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: parent
      namespace: agentgateway-system
    spec:
      hostnames:
      - delegation.example
      parentRefs:
      - name: agentgateway-proxy
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /anything/team1
        backendRefs:
        - group: gateway.networking.k8s.io
          kind: HTTPRoute
          name: child-team1
          namespace: team1
      - matches:
        - path:
            type: PathPrefix
            value: /anything/team2
        backendRefs:
        - group: gateway.networking.k8s.io
          kind: HTTPRoute
          name: child-team2
          namespace: team2
    EOF
  2. Create the child-team1 HTTPRoute in the team1 namespace that matches traffic on the /anything/team1/foo prefix and routes traffic to the httpbin app.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: child-team1
      namespace: team1
    spec:
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /anything/team1/foo
        backendRefs:
        - name: httpbin
          port: 8000
    EOF
  3. Create the child-team2 HTTPRoute in the team2 namespace that matches traffic on the /anything/team2/grandchild/ prefix and delegates traffic to a grandchild HTTPRoute in the team2 namespace. Because the child delegates to a grandchild, the rule must use a PathPrefix matcher.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: child-team2
      namespace: team2
    spec:
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /anything/team2/grandchild/
        backendRefs:
        - group: gateway.networking.k8s.io
          kind: HTTPRoute
          name: grandchild
          namespace: team2
    EOF
  4. Create a grandchild HTTPRoute that matches traffic on the /anything/team2/grandchild/.* regex path and routes traffic to the httpbin app in the team2 namespace.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: grandchild
      namespace: team2
    spec:
      rules:
      - matches:
        - path:
            type: RegularExpression
            value: /anything/team2/grandchild/.*
        backendRefs:
        - name: httpbin
          port: 8000
    EOF
  5. Send a request to the delegation.example domain along the /anything/team1/foo path. Verify that you get a 200 HTTP response.

    curl -i http://$INGRESS_GW_ADDRESS:8080/anything/team1/foo -H "host: delegation.example"

    Example output:

    HTTP/1.1 200 OK
    access-control-allow-credentials: true
    access-control-allow-origin: *
    content-type: application/json; encoding=utf-8
    server: agentgateway
  6. Send another request to the delegation.example domain along the /anything/team1/bar path. Verify that you get a 404 HTTP response, because this path is not specified in child-team1.

    curl -i http://$INGRESS_GW_ADDRESS:8080/anything/team1/bar -H "host: delegation.example"

    Example output:

    HTTP/1.1 404 Not Found
    content-type: text/plain
    server: agentgateway
  7. Send another request to the delegation.example domain. This time, use the /anything/team2/grandchild/bar path that is matched by the grandchild HTTPRoute. Verify that you get a 200 HTTP response.

    curl -i http://$INGRESS_GW_ADDRESS:8080/anything/team2/grandchild/bar -H "host: delegation.example"

    Example output:

    HTTP/1.1 200 OK
    access-control-allow-credentials: true
    access-control-allow-origin: *
    content-type: application/json; encoding=utf-8
    server: agentgateway
  8. Send another request along the /anything/team2/grandchild/foo path. Because the grandchild HTTPRoute uses a regular expression to match incoming traffic, any path that begins with /anything/team2/grandchild/ is routed to the httpbin app in the team2 namespace.

    curl -i http://$INGRESS_GW_ADDRESS:8080/anything/team2/grandchild/foo -H "host: delegation.example"

    Example output:

    HTTP/1.1 200 OK
    access-control-allow-credentials: true
    access-control-allow-origin: *
    content-type: application/json; encoding=utf-8
    server: agentgateway

Cleanup

You can remove the resources that you created in this guide.
kubectl delete httproute parent -n agentgateway-system
kubectl delete httproute child-team1 -n team1
kubectl delete httproute child-team2 -n team2
kubectl delete httproute grandchild -n team2
kubectl delete namespaces team1 team2
Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.