Sub topic 4
GatewayClass and Gateway
This chapter assumes you know the Ingress resource, have used an Ingress controller such as Ingress NGINX, and can apply YAML with kubectl. It covers the two Gateway API resources that replace the controller and its entry point.
From IngressClass to GatewayClass
With Ingress NGINX, the ingressClassName: nginx field selects a controller. The controller runs in your cluster, and the same Ingress object holds your routing rules and your TLS settings.
The Gateway API splits this into layers:
- A GatewayClass is a cluster-scoped resource that names the controller implementation. It is the counterpart of IngressClass. The platform or infrastructure provider usually installs it.
- A Gateway is a namespaced resource that asks for a load balancer or proxy of that class. It declares ports, protocols and TLS settings in a list of listeners.
Routes such as HTTPRoute hold the host and path rules. They come in a later chapter. This split lets a platform team own the Gateway while application teams own their routes.
Inspect the available classes
You normally do not write a GatewayClass yourself. Installing an implementation creates one. List them:
kubectl get gatewayclassThe CONTROLLER column shows which implementation owns each class. The ACCEPTED column should read True before you use the class.
Define a Gateway
This Gateway lives in a dedicated namespace and serves HTTP and HTTPS:
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:
namespaces:
from: All
- name: https
protocol: HTTPS
port: 443
hostname: app.example.com
tls:
mode: Terminate
certificateRefs:
- name: app-example-com-tls
allowedRoutes:
namespaces:
from: AllReplace example-class with a class from your own cluster. The fields map to what you know from Ingress as follows:
| Ingress concept | Gateway API field |
|---|---|
| `ingressClassName` | `gatewayClassName` |
| `spec.tls[].secretName` | `listeners[].tls.certificateRefs` |
| Ports 80 and 443 (implicit) | `listeners[].port` and `protocol` |
| Controller-wide settings | Listener and implementation-specific config |
Common mistakes
- The certificate Secret must be in the Gateway's namespace, here
gateway-system. Putting it in the application namespace, as you did with Ingress, leaves the listener unresolved. A later chapter shows how ReferenceGrant allows cross-namespace use. allowedRoutes.namespaces.from: Alllets any namespace attach routes. UseSameor a selector if you want tighter control.- A Gateway can be created before the controller accepts it. Check its status instead of assuming it works.
kubectl get gateway -n gateway-system
kubectl describe gateway shared-gateway -n gateway-systemLook for the Accepted and Programmed conditions, and for per-listener ResolvedRefs. These conditions replace the guesswork of reading controller logs.
Exercise
Your HTTPS listener reports ResolvedRefs as False. The Gateway is in gateway-system and the certificate Secret is in the shop namespace. What is the likely cause, and what are two ways to fix it?
Show answer
The listener cannot use a Secret from another namespace without permission. Either create the Secret in gateway-system, or add a ReferenceGrant in the shop namespace that allows Gateways from gateway-system to reference Secrets.