Lesson 32 of 70 · 8 min read · Updated
Gateway API with Traefik: Running the Same Routes on a Second Implementation
On this page
The main promise of the Gateway API is portability: a route written for one implementation should work on another. In this lesson, Traefik is installed next to NGINX Gateway Fabric in the same cluster, and the PedalShare stations HTTPRoute is attached to both Gateways at the same time. Then we look at what is different in Traefik: listener ports, a shared data plane, and Middlewares plugged into standard routes.
Technical Requirements
- The
gateway-labcluster with NGINX Gateway Fabric and the stations API from the previous lesson - Helm and the Traefik chart repository:
helm repo add traefik https://traefik.github.io/charts - Sample repository: Fcakiroglu16/dotnetacademy, branch gateway-api-traefik
| Component | Version |
|---|---|
| Traefik Proxy | 3.7.18 (chart traefik 42.4.0) |
| Gateway API supported by Traefik 3.7 | 1.6.3, Standard channel |
| NGINX Gateway Fabric (already installed) | 2.8.1 |
Core Concepts
Traefik's providers
Traefik reads routing configuration from providers. For Kubernetes there are three:
kubernetesIngress: classic Ingress objectskubernetesCRD: Traefik's ownIngressRouteandMiddlewareCRDskubernetesGateway: Gateway API resources
They can run together. In this lab, only the Gateway API provider routes traffic. The CRD provider stays enabled so that Middleware objects can be used from HTTPRoutes.
One data plane for every Gateway
NGF creates an NGINX Deployment for each Gateway. Traefik works the other way round: the Traefik Deployment installed by the chart is the data plane, and every Gateway of class traefik is configured into those same Pods. Creating a Gateway does not start new Pods.
Listener ports are entryPoint ports
Traefik listens on entryPoints defined in the chart's ports section. By default, web listens on container port 8000 (exposed as Service port 80), and websecure listens on 8443 (exposed as 443). A Gateway listener's port must match an entryPoint's container port. A listener on port 80 has no matching entryPoint and is rejected.
| NGINX Gateway Fabric | Traefik | |
|---|---|---|
| Data plane | NGINX Deployment and Service per Gateway | Shared Traefik Deployment |
Listener port | Port opened on the generated Service | Container port of an entryPoint (8000, 8443) |
Gateway status.addresses | IP of the generated Service | Empty unless statusAddress is configured |
| Non-standard features | Policies with targetRef (ClientSettingsPolicy, ...) | Middleware through an ExtensionRef filter |
| GatewayClass | nginx | traefik |
Hands-On: Kubernetes Commands
The chart values enable the Gateway API provider, disable the Ingress provider, and skip the chart's default Gateway because the platform team creates its own:
k8s/03-traefik/values.yaml
The chart does not install the Gateway API CRDs. Its install notes ask for v1.6.3, which the lab cluster already has. After the install, the cluster has two accepted GatewayClasses:
Useful commands for Traefik:
Step-by-Step Example
Step 1: A second Gateway for Traefik
The Gateway lives in the same pedalshare-infra namespace as the NGF one and uses the same allowedRoutes rule. Only the class and the port are different:
k8s/03-traefik/01-gateway.yaml
No new Pods appear in pedalshare-infra. Traefik configured the existing Pod in the traefik namespace.
Step 2: One route, two Gateways
The stations HTTPRoute gets a second parentRefs entry. Rules, hostnames and backends stay the same:
k8s/03-traefik/02-httproute-both.yaml
Each controller writes its own entry in status.parents:
Send the same request through both data planes (NGF on 8080, Traefik on 8081):
Both answers come from stations-api. The forwarded headers show which proxy handled the request: Traefik adds x-forwarded-server with its Pod name, and NGF adds x-real-ip and sets Server: nginx.
Running two implementations side by side like this is also a safe way to migrate: attach routes to the new Gateway, test it, then move DNS and remove the old parentRefs entry.
Step 3: The listener port mistake
A Gateway copied from the NGF lesson keeps port: 80. Traefik rejects it and says why:
k8s/03-traefik/03-wrong-port-gateway.yaml
The route side is portable, but Gateways contain infrastructure details such as ports, which may need changes when you switch implementations. That fits the role split: the platform team owns those details.
Step 4: A Traefik Middleware in a standard HTTPRoute
Unlocking a bike is a POST that should not be called in a loop. The Gateway API has no rate-limit filter, but it has ExtensionRef, which points a rule at an implementation-specific object. Traefik accepts its Middleware there:
k8s/03-traefik/04-ratelimit.yaml
The first four requests use the burst, and the rest get 429 Too Many Requests until the bucket refills at 2 requests per second. This route is attached only to public-traefik, so the same request through NGF returns 404. Routes that use an ExtensionRef are tied to the implementation that understands it.
Results
| Check | Result |
|---|---|
| Traefik chart 42.4.0 installed | traefik GatewayClass Accepted=True |
Gateway public-traefik on port 8000 | Programmed=True, no new Pods, no address in status |
Stations route with two parentRefs | Accepted by both controllers, 200 through NGF and Traefik |
| Gateway listener on port 80 | Accepted=False, listener reason PortUnavailable |
rateLimit Middleware via ExtensionRef (average 2, burst 4) | 10 quick POSTs: 4 × 200, then 6 × 429 |
| Same POST through NGF | 404, the route is not attached there |
Summary
- Traefik implements the Gateway API through its
kubernetesGatewayprovider. The chart registers thetraefikGatewayClass but does not ship the CRDs. - One Traefik Deployment serves every Gateway of its class. Listener ports must match entryPoint container ports, such as 8000 for
web. - A single HTTPRoute can attach to Gateways from different implementations, and each controller reports its own status. This makes side-by-side migration straightforward.
- Implementation-specific features enter standard routes through
ExtensionRef(Traefik Middleware) or policies (NGF). Use them knowing that those rules no longer move between implementations.
The rest of the series goes back to NGINX Gateway Fabric and looks at HTTPRoute matching and filters in detail.