Lesson 31 of 70 · 8 min read · Updated
Gateway API with NGINX Gateway Fabric: Installation, Routing and NGINX Extensions
On this page
In the previous lesson, the PedalShare Gateway stayed at Waiting for controller because nothing in the cluster implemented it. In this lesson, NGINX Gateway Fabric (NGF) becomes the controller. NGF is F5's Gateway API implementation, built on NGINX and maintained separately from the retired community Ingress NGINX controller.
By the end, the stations API is reachable through an NGINX data plane, broken routes explain themselves in status, and two NGF extensions are in use: NginxProxy for the data plane and ClientSettingsPolicy for request limits. The rest of the series uses this setup.
Technical Requirements
- The
gateway-labkind cluster from the previous lesson (scripts/cluster-up.sh), with Gateway API v1.6.3 CRDs - Helm 3.8+ (OCI chart support), kubectl, curl
- Sample repository: Fcakiroglu16/dotnetacademy, branch gateway-api-nginx-gateway-fabric
| Component | Version |
|---|---|
| NGINX Gateway Fabric | 2.8.1 (supports Gateway API 1.6.3, Kubernetes 1.32+) |
| NGINX OSS data plane | 1.31.7 |
| Kubernetes (kind) | 1.36.4 |
Core Concepts
Control plane and data plane
NGF runs two kinds of Pods:
- Control plane (
nginx-gatewaynamespace): one Deployment that watches Gateway API resources, validates them, writes status and generates NGINX configuration. - Data plane: for every
Gatewayof classnginx, NGF creates an NGINX Deployment and a Service in the Gateway's namespace, named<gateway>-nginx. The control plane pushes configuration to it over a gRPC channel secured with certificates made by the chart'scert-generatorJob.
Because each Gateway gets its own NGINX Pods, two teams' Gateways never share a process, and you can scale or tune each one separately.
How Gateway API maps to NGINX
| Gateway API | Generated NGINX config |
|---|---|
Listener (port: 80) | server { listen 80; } |
Route hostnames | server_name |
PathPrefix /stations | location /stations/ plus location = /stations |
backendRefs (Service) | upstream block with the endpoint IPs |
| A missing backend | proxy_pass http://invalid-backend-ref, which returns 500 |
NGF sends traffic to Pod IPs from EndpointSlices, not to the Service's ClusterIP, so the upstream block changes whenever the backend scales.
Extensions
NGF adds its own CRDs for features the Gateway API does not standardise. They attach to standard objects, so the routes stay portable:
NginxProxy: data plane settings (replicas, Service type, logging,server_tokens), referenced byGateway.spec.infrastructure.parametersRefor by the GatewayClass.ClientSettingsPolicy,ProxySettingsPolicy,UpstreamSettingsPolicy,RateLimitPolicy,ObservabilityPolicy: policies that target a Gateway or an HTTPRoute throughtargetRef.SnippetsFilterandSnippetsPolicy: raw NGINX directives, disabled by default.
Hands-On: Kubernetes Commands
Install NGF from its OCI chart. kind has no cloud load balancer, so the data plane Services use NodePort instead of the default LoadBalancer:
The chart registers the nginx GatewayClass, and NGF accepts it right away:
Commands you will use all the time with NGF:
Step-by-Step Example
Step 1: Deploy the stations API
The stations team's namespace carries the pedalshare.io/edge-access=true label that the Gateway selects on. The app is a .NET 10 minimal API that echoes the service name, the Pod, the path and the X-* headers it received, which makes it easy to see which backend answered.
Step 2: Create the Gateway
This is the Gateway from the fundamentals lesson. The only change is gatewayClassName: nginx.
k8s/02-nginx-gateway-fabric/01-gateway.yaml
NGF created public-nginx next to the Gateway, and the Gateway's address is that Service's IP.
Step 3: Attach the HTTPRoute
k8s/02-nginx-gateway-fabric/02-httproute.yaml
Forward a local port to the data plane and send a request with the route's hostname:
kubectl port-forward exits after one broken connection, which can happen when NGINX reloads. scripts/port-forward.sh in the repository restarts it in a loop and is used in the rest of the series.
The route's status shows which controller accepted it, and the Gateway counts attached routes per listener:
Step 4: Read the status of broken routes
03-broken-routes.yaml adds two common mistakes: a route in a namespace without the label (pedalshare-sandbox), and a route whose Service docks-api does not exist.
The sandbox route is not attached at all, so its hostname returns 404. The docks route is attached, but its rule has no valid backend, so NGINX answers 500 for /docks instead of passing the request to another backend. The generated configuration shows both routes:
Step 5: Tune the data plane with NginxProxy
The platform team wants two NGINX replicas and no version number in the Server header. The Gateway references an NginxProxy through infrastructure.parametersRef:
k8s/02-nginx-gateway-fabric/04-nginxproxy.yaml
Step 6: Limit request bodies with ClientSettingsPolicy
Station reviews are short text, so the stations team caps request bodies at 1 KB for its route. The policy targets the HTTPRoute, and NGF reports in the policy's status whether it was applied:
k8s/02-nginx-gateway-fabric/05-clientsettings.yaml
Results
| Check | Result |
|---|---|
nginx GatewayClass after install | Accepted=True |
Gateway public | Programmed=True, public-nginx Deployment and Service created in pedalshare-infra |
GET /stations/42 with the right host | 200 from stations-api |
| Unknown path or host | 404 |
| Route from an unlabelled namespace | Accepted=False NotAllowedByListeners, not attached |
| Route with a missing Service | Accepted=True, ResolvedRefs=False BackendNotFound, requests return 500 |
NginxProxy with replicas: 2 | Data plane scaled to 2 Pods, Server: nginx without version |
ClientSettingsPolicy maxSize: 1k | 2.7 KB body returns 413, small body returns 200 |
Summary
- NGF is installed with one Helm chart and registers the
nginxGatewayClass. Each Gateway gets its own NGINX Deployment and Service in the Gateway's namespace. - Listeners, hostnames and route matches turn into NGINX
serverandlocationblocks, andnginx -Tshows the result. - Route problems appear in
status.parents[].conditions. A missing backend returns 500 for that rule only. NginxProxyand the NGF policies extend the standard objects throughparametersRefandtargetRef, so the HTTPRoutes stay portable.
In the next lesson, Traefik implements the same Gateway API resources, and the stations HTTPRoute runs on it without changes.