Sub topic 4
Gateway: requesting a traffic entry point
This chapter assumes you know Pods, Services, Namespaces, and labels, and that you can apply YAML with kubectl. It also assumes you have read the previous chapter on GatewayClass.
What a Gateway is
A Gateway is a namespaced resource that asks a controller for a traffic entry point. The entry point might be a cloud load balancer or a proxy Deployment. Which one you get depends on the implementation.
A Gateway does not describe where requests go. It describes where traffic may enter: which class of controller handles it, which ports and protocols it listens on, and which routes may attach. Routing rules live in route resources such as HTTPRoute, which the later chapters cover.
Cluster operators usually own Gateways. They typically live in a shared infrastructure namespace.
A minimal Gateway
This Gateway lives in the infra namespace. It asks the example-class controller for an HTTP listener on port 80. It accepts routes only from namespaces labeled shared-gateway-access=true.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: web-gateway
namespace: infra
spec:
gatewayClassName: example-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: Selector
selector:
matchLabels:
shared-gateway-access: "true"The fields that matter
gatewayClassNameis required. It must name an existing GatewayClass. If the class does not exist or its controller does not accept it, nothing is provisioned.listenersis a list with at least one entry. Each listener has aname, aprotocol, and aport.- Listener names must be unique within the Gateway. Routes can use them to attach to one specific listener.
allowedRouteslimits which namespaces, and which route kinds, may bind to the listener. Without it, only routes from the Gateway's own namespace attach.
The next chapter covers listeners in more detail.
Creating and checking it
Apply the manifest, then read the status the controller writes back.
kubectl get gatewayclass
kubectl get gateway -n infra web-gateway -o yamlLook at status.conditions. Two conditions matter first:
| Condition | Meaning when True |
|---|---|
| Accepted | The controller has accepted the Gateway configuration. |
| Programmed | The entry point is configured and can pass traffic. |
The status.addresses field shows the IP address or hostname clients should use. It stays empty until the entry point exists.
Common errors
- Wrong
gatewayClassName. The Gateway stays unaccepted. Runkubectl get gatewayclassand check that the class exists and shows Accepted. - No controller installed. The resources are valid, but no status appears, because nothing is watching them.
- Routes in the wrong namespace. The Gateway is healthy, but a route from an unlabeled namespace never attaches. Check the namespace labels against the
allowedRoutesselector. - Duplicate listener ports and protocols. Listeners that conflict with each other get a Conflicted condition.
Exercise
A Gateway in the infra namespace shows Accepted=True but Programmed=False, and status.addresses is empty. Is the problem more likely in the GatewayClass reference or in the allowedRoutes selector? Explain.
Show answer
Neither is the most likely cause. Accepted=True means the controller accepted the class reference, so gatewayClassName is fine. allowedRoutes only decides which routes may attach, and it does not affect whether the entry point is programmed. The likely cause is that the controller has not finished provisioning the load balancer or proxy. Read the message and reason on the Programmed condition with kubectl get gateway -o yaml, and check the controller's logs and cloud quota.