Gateway API roles and attachment
Three objects, three responsibilities
Gateway API extends Kubernetes with separately installed custom resources and an implementation that reconciles them. GatewayClass is cluster-scoped and names the controller; a Gateway instance requests listeners and infrastructure; an HTTPRoute describes HTTP routing for an application. The platform team can manage the Gateway in edge-study while the application team manages the HTTPRoute in shop-study. This is a useful separation of permissions, not automatic isolation. The examples use the v1 forms documented in Gateway API 1.5, including ReferenceGrant. Older installations may expose different versions; check the installed CRDs and controller support.
apiVersion: gateway.networking.k8s.io/v1kind: GatewayClassmetadata: name: offline-studyspec: controllerName: example.invalid/offline-controllerDefine a listener and its attachment policy
The following Gateway listens for HTTPS on port 443 for shop.example.test. The certificate reference is local to edge-study. Only namespaces with the specified label may attach compatible routes. If allowedRoutes is omitted, same-namespace attachment is the default. The label must belong to the Namespace object, not merely the Route. The platform team must control who can set that label. A cross-namespace parent reference alone cannot override the listener restrictions.
apiVersion: gateway.networking.k8s.io/v1kind: Gatewaymetadata: name: shop namespace: edge-studyspec: gatewayClassName: offline-study listeners: - name: https hostname: shop.example.test port: 443 protocol: HTTPS tls: mode: Terminate certificateRefs: - name: edge-study-tls allowedRoutes: namespaces: from: Selector selector: matchLabels: study-access: shopAttach an application route
parentRefs names the Gateway and its namespace. sectionName selects the listener named https. The Route hostname must intersect the listener hostname. Rules match HTTP paths and forward to local Services; Gateway API uses PathPrefix rather than the Ingress spelling Prefix. Route attachment requires both sides to agree. HTTPRoute can also support richer matching, filters or weighted backend references; verify the feature and implementation rather than assume every extension works. Other route types serve different protocols (for example GRPCRoute or TLSRoute); discover installed versions and conformance before using them.
apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata: name: shop namespace: shop-studyspec: parentRefs: - name: shop namespace: edge-study sectionName: https hostnames: - shop.example.test rules: - matches: - path: type: Exact value: /api/health backendRefs: - name: health port: 80 - matches: - path: type: PathPrefix value: /api backendRefs: - name: inventory port: 80 - matches: - path: type: PathPrefix value: / backendRefs: - name: frontend port: 80Authorize a different backend namespace
If an HTTPRoute in shop-study refers to inventory in data-study, that backend namespace must permit the reference. The following ReferenceGrant allows HTTPRoute objects from shop-study to reference the named Service inventory in data-study. It does not grant API write privileges, open network paths or permit arbitrary target Services. Cross-namespace attachment to a Gateway uses allowedRoutes instead, not this grant. The baseline route still references the local inventory; cross-namespace cases are hypothetical variations. For v1.5 the v1 resource is documented; check served versions before choosing an older manifest.
apiVersion: gateway.networking.k8s.io/v1kind: ReferenceGrantmetadata: name: allow-shop-inventory namespace: data-studyspec: from: - group: gateway.networking.k8s.io kind: HTTPRoute namespace: shop-study to: - group: '' kind: Service name: inventoryRead status per parent and generation
Inspect HTTPRoute status.parents for the relevant parent and controller. Accepted reports whether the route has been accepted for that parent; ResolvedRefs reports reference validity. A denied listener and a missing backend grant are distinct problems. A route may be accepted while a backend reference is invalid. Inspect Gateway and listener conditions including Programmed as applicable, and compare observedGeneration to metadata.generation to avoid relying on stale status. These conditions do not establish that the backend application is healthy or that network policy allows traffic. Inspect the endpoints and actual requests separately.
Synthetic case: Accepted=True, ResolvedRefs=False (RefNotPermitted)Next step: review the backend reference and the target namespace grant; do not broaden permissions.Practice the two permissions
Use attachment-cases.json and grant-cases.json to decide whether the route may attach and whether its backend reference is authorized. Explain why a valid reference and accepted route are not equivalent to a successful HTTP response. All files are offline study objects with a fictional controller and missing certificate; they must not be applied.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Gateway API roles and attachment — knowledge check
Interpret offline HTTP routing and migration evidence.
Which object identifies the Gateway controller implementation?
Which setting governs cross-namespace attachment to a Gateway listener?
Where is a ReferenceGrant for a backend Service created?
What can Accepted=True and ResolvedRefs=False mean?
What does sectionName https select in the example?