Gateway API: Expose your services running on Kubernetes

The Gateway API is the next evolution of Kubernetes networking. It effectively replaces the older Ingress API, offering a more expressive, extensible, and role-oriented way to model service networking.
We are going to explore how to set up and use the Gateway API with practical examples. We'll look at exposing services to the internet, handling local traffic, and securing it all using Cilium as our underlying implementation (Note: it can be something else, it doesn't change the logic).
How it works
At its core, Gateway API separates the concerns of infrastructure provisioning from application routing.
- GatewayClass: Defines the type of controller that will manage the Gateways (in our case,
cilium). - Gateway: Describes a load balancer or ingress point that listens for traffic.
- HTTPRoute: Defines the rules for routing HTTP/HTTPS traffic from a Gateway to your Services.
- TLSRoute: Routes TLS streams based on SNI (Server Name Indication), often used for TLS passthrough.
- TCPRoute & UDPRoute: Handle raw Layer 4 traffic for non-HTTP protocols like databases.
- GRPCRoute: Specialized routing for gRPC traffic, allowing matches on services and methods.
The Internet-Facing Gateway
Let's start with the most common requirement: exposing applications to the world. We want automatic DNS management and TLS termination.
We define a Gateway specifically for internet traffic. Notice how we use annotations to delegate heavy lifting to cert-manager and external-dns.
Routing Traffic
Now that the door is open, we need to guide the traffic. We use an HTTPRoute to send requests matching our hostnames to the correct service.
The Local Gateway
Sometimes we want services available only within our home or private network. We can create a separate "Local" Gateway for this purpose. This keeps internal tools internal.
Cross-Namespace Access
One tricky part of Gateway API is security boundaries. By default, a Gateway in kube-system cannot read a Secret (like your TLS certificate) from cert-manager namespace.
We solve this with a ReferenceGrant. It explicitly allows the Gateway to reference secrets in another namespace.
Redirects
A very common pattern is redirecting insecure HTTP traffic to HTTPS. Gateway API handles this elegantly with Filters.
Here, we attach to the http listener of our local gateway and apply a RequestRedirect filter to upgrade the scheme to HTTPS.
Security with Cilium Network Policies
Finally, even with a Gateway, we should restrict network traffic. We can use a CiliumNetworkPolicy to ensure that only specific CIDR ranges (like our home network subnets) can talk to the Gateway.
This policy locks down the local gateway so strictly clients from 192.168.94.0/24 and 192.168.27.0/24 can connect to it.