API Gateways, Traffic Management & the Edge›03 · Gateway API in depth

Lesson 03 of 13 · The big picture

Gateway API in depth

The Gateway API object by object: GatewayClass, Gateway and its listeners, routes and how they attach, matches and filters (redirects, rewrites, header changes, mirroring, timeouts), cross-namespace references with ReferenceGrant, backend TLS, and the status conditions that tell you why a route doesn't work, with real status messages from a test cluster.

Intermediate → Advanced
Key wordsGateway APIGatewayClassGatewaylistenerallowedRoutesHTTPRouteGRPCRouteTLSRouteReferenceGrantBackendTLSPolicyListenerSetparentRefsbackendRefsmatchesfiltersRequestRedirectURLRewriteRequestHeaderModifierRequestMirrortimeoutsroute statusAcceptedResolvedRefsProgrammedconformancestandard channelexperimental channel

Roles first

The Gateway API splits ownership the way real organisations work:

Role Owns Decides
Infrastructure provider GatewayClass Which controller and which default settings
Platform / cluster operator Gateway Ports, hostnames, certificates, which namespaces may attach
Application developer HTTPRoute, GRPCRoute Paths, headers, weights, filters, backends in their namespace

App teams change routes all day without touching certificates or ports; the platform team controls the entry point without approving every path. A first walk-through is in Gateway API; this lesson goes deeper.

infrastructure provider GatewayClass controller: envoy platform team Gateway listeners: http, https certificates allowed namespaces namespace shop (app team) HTTPRoute /orders → v1 90 %, v2 10 % x-version: v2 → v2 Services orders-v1 orders-v2 parentRef only with the grant namespace payments (another team) ReferenceGrant allows routes from shop Service payments
GatewayClass names the controller; the platform team's Gateway defines listeners and who may attach; app teams attach Routes from their own namespaces.

A shopping centre: the owner picks the security company (GatewayClass), the centre manager decides which entrances are open and which shops may put up signs at each one (Gateway), and every shop writes its own signs pointing to its counter (Routes). A shop can't point a sign at another shop's storeroom unless that shop agrees (ReferenceGrant).

GatewayClass and Gateway

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: envoy
spec:
  controllerName: gateway.envoyproxy.io/gatewayclass-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: edge
  namespace: infra
spec:
  gatewayClassName: envoy
  listeners:
  - name: http
    protocol: HTTP
    port: 80
    allowedRoutes:
      namespaces:
        from: Selector                     # only namespaces with this label may attach
        selector:
          matchLabels:
            edge-access: "true"
  - name: https
    protocol: HTTPS
    port: 443
    hostname: api.example.test
    tls:
      mode: Terminate
      certificateRefs:
      - kind: Secret
        name: api-tls                      # in the Gateway's namespace
    allowedRoutes:
      namespaces:
        from: Selector
        selector:
          matchLabels:
            edge-access: "true"
  • A listener = port + protocol (+ hostname, TLS). One Gateway can have many.
  • allowedRoutes.namespaces.from: Same (default), All, or Selector. Use Selector on shared gateways.
  • Each Gateway usually becomes a set of proxy pods plus a Service; PROGRAMMED=True means the data plane is configured and has an address.

Routes: matches, filters, backends

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: orders
  namespace: shop
spec:
  parentRefs:
  - name: edge
    namespace: infra
    sectionName: https                   # attach to one listener only (optional)
  hostnames: ["api.example.test"]
  rules:
  - matches:
    - path: { type: PathPrefix, value: /orders }
      headers:
      - { name: x-version, value: v2 }
    backendRefs:
    - { name: orders-v2, port: 80 }
  - matches:
    - path: { type: PathPrefix, value: /orders }
    backendRefs:
    - { name: orders-v1, port: 80, weight: 90 }
    - { name: orders-v2, port: 80, weight: 10 }
    timeouts:
      request: 5s
  - matches:
    - path: { type: PathPrefix, value: /old-orders }
    filters:
    - type: RequestRedirect
      requestRedirect:
        path: { type: ReplacePrefixMatch, replacePrefixMatch: /orders }
        statusCode: 301

Matching: path (Exact, PathPrefix, RegularExpression), headers, query parameters, method. When several rules match, the most specific wins (exact path over prefix, longer prefix over shorter, more header matches over fewer).

Filters change the request or response on the way:

Filter Use
RequestRedirect http → https, old path → new path (301/302)
URLRewrite Rewrite host or path before sending to the backend
RequestHeaderModifier / ResponseHeaderModifier Add, set or remove headers
RequestMirror Send a copy of traffic to another backend; responses are ignored (testing a new version on real traffic)
ExtensionRef Implementation-specific filters

Other route types: GRPCRoute (match on gRPC service and method), TLSRoute (route encrypted traffic by SNI without terminating it), TCPRoute and UDPRoute.

Crossing namespaces safely: ReferenceGrant

A route may only point to Services in its own namespace, and a Gateway may only use certificates in its own namespace, unless the other namespace's owner agrees:

# In namespace payments: allow HTTPRoutes from shop to reference our Services
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: allow-shop-routes
  namespace: payments
spec:
  from:
  - group: gateway.networking.k8s.io
    kind: HTTPRoute
    namespace: shop
  to:
  - group: ""
    kind: Service

This stops one team from sending public traffic to another team's internal service without asking.

Backend TLS

By default the gateway talks plain HTTP to backends. BackendTLSPolicy tells it to use TLS to a Service, which CA to trust and which hostname to verify, for backends that require encryption (or use a mesh for mTLS instead).

Status: the first place to look

Every object reports what the controller made of it. Real messages from a test cluster (Envoy Gateway 1.10, Gateway API 1.6):

# A Gateway on kind before it had an address
Accepted=True Accepted: The Gateway has been scheduled by Envoy Gateway
Programmed=False AddressNotAssigned: No addresses have been assigned to the Gateway

# A route whose Service doesn't exist
Accepted=True Accepted: Route is accepted
ResolvedRefs=False BackendNotFound: Failed to process route rule 0 backendRef 0: service shop/payments not found.
$ curl -H 'Host: api.example.test' localhost:8080/payments     →  500

# A route from a namespace the listener doesn't allow
Accepted=False NotAllowedByListeners: No listeners included by this parent ref allowed this attachment.

# Listener summary on the Gateway
http: attachedRoutes=2 Programmed=True
https: attachedRoutes=1 Programmed=True
Condition Where Meaning when False
Accepted Gateway, Route (per parent) The controller rejected it: wrong class, listener doesn't allow the namespace, hostname mismatch, invalid config
ResolvedRefs Route, listener A backend, Secret or reference is missing or not permitted
Programmed Gateway, listener The data plane isn't ready, or no address was assigned

Versions and channels

  • Gateway API is installed as CRDs, separately from Kubernetes. Implementations document which Gateway API version they support; some (like Envoy Gateway's Helm chart) install the CRDs for you.
  • Standard channel: stable resources and fields. Experimental channel: newer ones (some route types and fields before they graduate). Check which channel your CRDs come from before relying on a field.
  • Conformance reports show which features each implementation passes.

Try it

Use the cluster from lesson 4 (or any Gateway API implementation):

  1. Add the /old-orders redirect rule and check the Location header with curl -si.
  2. Create an HTTPRoute in a namespace without the edge-access label and read its status.
  3. Point a route at a Service in another namespace; read the status; add a ReferenceGrant; read it again.
  4. Add a RequestHeaderModifier that sets x-served-by: gateway and confirm the echo server receives it.

Going deeper

  • ListenerSet lets app teams contribute listeners (for example their own hostname and certificate) to a shared Gateway without editing it.
  • Policy attachment: implementations attach extra policies (security, traffic, TLS) to Gateways or Routes with targetRefs; the most specific attachment wins.
  • Keep one shared Gateway per environment and trust boundary (public, partner, internal) rather than one per team; it reduces load balancers and certificates to manage.

Recap

  • GatewayClass (controller), Gateway (listeners, platform-owned) and Routes (app-owned) split responsibility cleanly.
  • Routes match on path, headers, query and method; filters redirect, rewrite, modify headers and mirror; weights split traffic.
  • Cross-namespace references need a ReferenceGrant from the target namespace.
  • Read status conditions first: Accepted, ResolvedRefs, Programmed, with reasons that usually name the problem.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.