FIELD NOTESKUBERNETES

The Gateway API for people who know Ingress

Every Ingress idea has a Gateway API home: GatewayClass, a Gateway that holds the certificate, HTTPRoutes per team. The reason to move is who owns which piece, and where that split is only ceremony.

By Kevin4 min readPublished
ON THIS PAGE
One Ingress cut in two: in namespace infra the platform team's GatewayClass, shared Gateway and TLS Secret; in namespaces shop and blog each app team's HTTPRoute and Service, attached through the listener's allowed namespaces. Drawn in archhy.

If you know Ingress, you already know most of the Gateway API: hosts, paths, backends, a certificate, a class that picks the controller. What changes is who writes each piece. An Ingress puts the controller choice, the certificate and the app's paths in one object, edited by whoever can edit it. The Gateway API cuts that object in two, so the platform team owns the entrance and its certificate and each app team owns its routes. That split is the reason to move. The extra YAML is what it costs, and on a cluster run by one team it buys you less than the diagrams suggest.

Based on the article from Gazeek, our sister site for hands-on CKA and CKAD labs: Blue/green deployments with the Gateway API. The complete Gateway and HTTPRoute, a weighted release and the status checks are there; this page is the map from what you know.

Where each Ingress idea went#

  • IngressClass becomes GatewayClass. Same job: it names the controller, cluster-wide.
  • The front door becomes an object. With ingress-nginx, the load balancer was a side effect of installing the controller. A Gateway is something you declare, with listeners (port, protocol, optional hostname), and a cluster can have several.
  • The certificate moves house. spec.tls on the Ingress becomes certificateRefs on a Gateway listener, out of the app's object.
  • Hosts, paths and backends become an HTTPRoute's hostnames, matches and backendRefs. Matches can also test headers, query parameters and the method, and each backend can carry a weight.
  • Annotations become fields. Rewrites, redirects, header changes and canary weights are standard filters and weights, so they mean the same thing on every conformant implementation instead of only on the controller that invented the annotation.
  • Snippets become nothing. Raw NGINX configuration has no standard home. If you depended on it, you are now reading your implementation's own policy resources.

Who owns what#

The Kubernetes documentation describes three roles, and the objects follow them. Whoever provides the infrastructure installs the GatewayClass. The cluster operator owns Gateways: listeners, certificates, and which namespaces may use them. Application developers own HTTPRoutes in their own namespaces.

Because these are separate kinds, ordinary RBAC can enforce the split. A team can be allowed to create HTTPRoutes and nothing else. With Ingress there was no such line: anyone who could edit an Ingress could set any annotation the controller honoured. That is how a snippet annotation became a way to read every Secret in the cluster (CVE-2021-25742), and why ingress-nginx later switched snippets off by default.

Attachment is a handshake, and it fails quietly#

A route names the Gateway it wants in parentRefs. The Gateway's listener decides which namespaces it accepts, and the default is its own namespace only. So the first thing an Ingress user hits is this: a shared Gateway in an infra namespace, a team's route in shop, both valid, and no traffic.

YAML
# on the Gateway, owned by the platform team
listeners:
- name: https
  port: 443
  protocol: HTTPS
  allowedRoutes:
    namespaces:
      from: Selector
      selector:
        matchLabels:
          gateway-access: shared
# on the HTTPRoute, owned by the app team
parentRefs:
- name: shared-gateway
  namespace: infra

Both halves have to agree. When they do not, nothing returns an error: the route reports Accepted: False, reason NotAllowedByListeners, in its status. With Ingress, a mistake usually showed up as a 404 you could curl. Here the habit to build is reading the route's status before reading any logs.

The same rule appears again for backends. A route that sends traffic to a Service in another namespace needs a ReferenceGrant, and the grant is created in the Service's namespace, not the route's. Throughout the API, the side that owns the thing being reached is the side that says yes. Seen that way, the extra objects are the permissions model Ingress never had.

When the split pays, and when it does not#

On a cluster shared by several teams, it pays at once. The platform team can rotate a certificate, add a listener or change the implementation behind the GatewayClass without touching a single route, and a team can release a canary without asking anyone for an annotation.

On a cluster where one team runs one app, the same person writes both objects, and the role model is ceremony. Move anyway, for the other reasons: ingress-nginx is retired (see ingress-nginx is retired: what now?), and weights, header matches and redirects are now standard fields. Keep both objects in one folder; when a second team arrives, the boundary is already drawn.

To convert existing Ingresses rather than rewrite them, read ingress2gateway: what it converts and what it leaves to you. To see weights doing real work, blue/green with the Gateway API releases a version by changing two numbers. To try it on a real cluster, Gazeek's CKA Ingress and network policy module builds an Ingress first and then the same routing with the Gateway API.

The diagram#

One cluster, two kinds of owner: the platform team's GatewayClass and shared Gateway on one side, two teams' HTTPRoutes and Services on the other, with the namespace handshake between them. Open it in archhy and press Make a copy to adapt it.

Go deeper#

Gazeek's full article has the Gateway and HTTPRoute YAML in full, the commands to test both versions, the weight patch and the mistakes that catch people out.