Sub topic 7
Attaching routes to Gateways
This chapter assumes you know the Gateway and HTTPRoute resources from the earlier chapters and can read kubectl describe output. It covers how a route is connected to a Gateway and why a route can exist without ever receiving traffic.
Attachment needs agreement from both sides
An Ingress names a class, and the controller picks it up. The Gateway API is stricter. A route attaches to a Gateway only when both sides agree:
- The route asks to attach through
parentRefs. - The Gateway listener allows that route through
allowedRoutes.
If either side does not agree, the route is not attached. The Gateway's owner (the platform team) controls who may attach, and the route's owner (the application team) controls where the route points.
The route side: parentRefs
In the earlier HTTPRoute, this block is the route's request to attach:
parentRefs:
- name: shared-gateway
namespace: gateway-system
sectionName: httpsname and namespace select the Gateway. sectionName selects one listener by its name. If you omit sectionName, the route tries to attach to every listener on that Gateway that allows it. Always set it during a migration, so the redirect route binds only to the http listener and the application route binds only to https.
The Gateway side: allowedRoutes
Each listener limits which routes can attach. The default is from: Same, meaning only routes in the Gateway's own namespace. That default surprises teams whose routes live in shop while the Gateway lives in gateway-system.
| `namespaces.from` | Routes allowed from |
|---|---|
| `Same` (default) | The Gateway's namespace only |
| `All` | Every namespace |
| `Selector` | Namespaces whose labels match a selector |
All is convenient but lets any team attach to your listener. Selector is a safer default for shared Gateways:
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: shared-gateway
namespace: gateway-system
spec:
gatewayClassName: example-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
kinds:
- kind: HTTPRoute
namespaces:
from: Selector
selector:
matchLabels:
shared-gateway-access: "true"Label the namespace with kubectl label namespace shop shared-gateway-access=true, and routes in shop can attach to this listener.
Common errors
- Wrong
sectionName. A typo such assectionName: httpon a route meant for HTTPS leaves the route bound to the wrong listener, or to none. - Namespace not allowed. The route reports
Accepted: Falsewith reasonNotAllowedByListeners. Checkfromand the namespace labels. - Hostname mismatch. If the listener sets
hostname: app.example.com, a route whose hostnames do not intersect with it is not accepted (reasonNoMatchingListenerHostname). - Unsupported kind. A listener that lists
kindsrejects any other route type.
Check the result in the route's status, under status.parents:
kubectl describe httproute app -n shopLook for Accepted: True and ResolvedRefs: True in each parent entry.
Exercise
An HTTPRoute in namespace shop has a correct parentRefs entry for a listener whose allowedRoutes section is omitted. The route shows Accepted: False. What is the likely cause, and what are two ways to fix it?
Show answer
The default is from: Same, so only routes in the Gateway's own namespace can attach. Either set allowedRoutes.namespaces.from to All or to Selector (and label the shop namespace to match), or move the route into the Gateway's namespace.