For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Native Gateway API policies
Learn how Kubernetes Gateway API policies, such as request timeouts, are inherited and overridden along the route delegation chain.
Verified Code examples on this page have been automatically tested and verified.Learn how policy inheritance and overrides work for Kubernetes Gateway API-native policies in a route delegation setup.
AgentgatewayPolicy resources? See AgentgatewayPolicy resources.About policy inheritance
Kubernetes Gateway API policies that can be defined on an HTTPRoute, such as timeouts and retries, are inherited as follows:
- Policies that are defined on a parent HTTPRoute are automatically inherited by all child or grandchild HTTPRoutes.
- If the child or grandchild HTTPRoute defines a policy, this policy takes precedence and overrides the policy that is set on the parent.
Configuration overview
In this guide, you set up a route delegation chain where a child HTTPRoute inherits or overrides a timeout that is set on the parent HTTPRoute. The child routes use a URLRewrite filter to expose httpbin’s /delay/N endpoint, which holds a request open for N seconds. You verify the inherited or overridden timeout by sending a request that takes longer than the timeout to complete.
The following image illustrates the route delegation hierarchy and policy inheritance:
parent HTTPRoute:
- Delegates traffic as follows:
/anything/team1is delegated to the child HTTPRoutechild-team1in namespaceteam1. The rule defines a1srequest timeout./anything/team2is delegated to the child HTTPRoutechild-team2in namespaceteam2. The rule also defines a1srequest timeout.
child-team1 HTTPRoute:
- Matches incoming traffic for the
/anything/team1/delayprefix path. Rewrites the prefix to/delayand routes traffic to the httpbin app in theteam1namespace. - Does not define a timeout, so it inherits the
1stimeout from the parent’s/anything/team1rule.
child-team2 HTTPRoute:
- Matches incoming traffic for the
/anything/team2/delayprefix path. Rewrites the prefix to/delayand routes traffic to the httpbin app in theteam2namespace. - Defines a custom
5srequest timeout that overrides the1stimeout from the parent’s/anything/team2rule.
Before you begin
Follow the Get started guide to install agentgateway.
Follow the Sample app guide to create the
agentgateway-proxyGateway with an HTTP listener.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_ADDRESSCreate the namespaces for
team1andteam2.kubectl create namespace team1 kubectl create namespace team2Deploy the httpbin app into both namespaces. The httpbin app exposes endpoints such as
/anything/...,/headers, and/delay/Nthat 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 -Verify that the httpbin apps are up and running.
kubectl get pods -n team1 kubectl get pods -n team2Example 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
Create the parent HTTPRoute that matches incoming traffic on the
delegation.exampledomain. Each rule defines a1srequest timeout.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: parent namespace: agentgateway-system spec: parentRefs: - name: agentgateway-proxy hostnames: - "delegation.example" rules: - matches: - path: type: PathPrefix value: /anything/team1 backendRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: child-team1 namespace: team1 timeouts: request: 1s - matches: - path: type: PathPrefix value: /anything/team2 backendRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: child-team2 namespace: team2 timeouts: request: 1s EOFCreate the
child-team1HTTPRoute. The HTTPRoute matches/anything/team1/delayand uses aURLRewritefilter to forward traffic to httpbin’s/delayendpoint. The route does not define a timeout, so the1stimeout from the parent is inherited.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/delay filters: - type: URLRewrite urlRewrite: path: type: ReplacePrefixMatch replacePrefixMatch: /delay backendRefs: - name: httpbin port: 8000 EOFCreate the
child-team2HTTPRoute. The HTTPRoute matches/anything/team2/delay, forwards to httpbin’s/delayendpoint, and defines a custom5srequest timeout that overrides the parent’s1stimeout.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/delay filters: - type: URLRewrite urlRewrite: path: type: ReplacePrefixMatch replacePrefixMatch: /delay backendRefs: - name: httpbin port: 8000 timeouts: request: 5s EOFSend a request to the
delegation.exampledomain along the/anything/team1/delay/3path. The httpbin app holds the request open for 3 seconds, but the inherited1stimeout cuts the request short. You get a 504 HTTP response after about 1 second.time curl -i --max-time 8 http://$INGRESS_GW_ADDRESS:8080/anything/team1/delay/3 \ -H "host: delegation.example"Example output:
HTTP/1.1 504 Gateway Timeout content-type: text/plain server: agentgateway curl ... total 1.034Send a request along the
/anything/team2/delay/3path. Thechild-team2route’s5stimeout overrides the parent’s1stimeout, so the 3-second httpbin delay completes. You get a 200 HTTP response after about 3 seconds.time curl -i --max-time 8 http://$INGRESS_GW_ADDRESS:8080/anything/team2/delay/3 \ -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 curl ... total 3.032
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 namespaces team1 team2