Sub topic 3
GatewayClass: choosing a controller
This chapter assumes you know Pods, Services, Namespaces, and labels, and that you can apply YAML with kubectl. It covers the first resource in the Gateway API chain: the GatewayClass.
What a GatewayClass is
A GatewayClass is a cluster-scoped resource. It names the controller that will manage every Gateway that references the class. It plays the same role for Gateways that a StorageClass plays for volumes. The infrastructure provider, or whoever installs the controller, usually owns it.
A GatewayClass does not create a load balancer or open a port. It only links a name to an implementation. Gateways that reference the class do the actual work.
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: example-class
spec:
controllerName: example.com/gateway-controllerThe controllerName field
spec.controllerName identifies the controller. The implementation you install defines the value, so copy it from that implementation's documentation. The format is a domain-prefixed path, such as example.com/gateway-controller.
When a controller starts, it looks for GatewayClass resources whose controllerName matches its own. It then handles every Gateway that points at one of those classes. A class whose controllerName matches no running controller is never accepted, and its Gateways stay unprogrammed.
Several classes can exist in one cluster. For example, you might have one class for an internet-facing load balancer and another for internal traffic. Each Gateway picks one class through spec.gatewayClassName.
The diagram below shows the relationship.
Checking that a class is accepted
The controller reports whether it has taken ownership of a class through status conditions. The key condition is Accepted. If it is True, a controller recognized the class and can serve Gateways that use it.
kubectl get gatewayclass
kubectl describe gatewayclass example-classThe kubectl get output includes the controller name and an ACCEPTED column. If the column shows Unknown or False, check the following:
- The Gateway API CRDs are installed at a version the controller supports.
- The controller Pod is running.
- The
controllerNamein the class matches the value the controller expects, character for character.
kubectl describe shows the condition's reason and message. These usually say why the controller did not accept the class.
Who changes what
Because a GatewayClass is cluster-scoped, only users with cluster-level permissions should create or edit it. Changing a class affects every Gateway that references it. Application developers normally never touch it. They work with Routes, and the cluster operator works with Gateways.
Exercise
A Gateway references a GatewayClass named edge, but the Gateway never becomes programmed. kubectl get gatewayclass shows edge with ACCEPTED set to Unknown. Name two likely causes.
Show answer
Likely causes include a controller that is not running or not installed, and a controllerName in the class that does not match the value the installed controller uses. Missing or unsupported Gateway API CRDs are a third possibility. In every case no controller has accepted the class, so Gateways that use it are not programmed.