traefik/traefik
Kubernetes providers
Kubernetes routing is by far the largest provider surface. Five separate providers live under pkg/provider/kubernetes/, each handling a different resource model.
The five providers
| Provider | Package | Resources |
|---|---|---|
| Ingress | pkg/provider/kubernetes/ingress |
Standard networking.k8s.io/v1.Ingress. |
| IngressRoute (CRD) | pkg/provider/kubernetes/crd |
Traefik's own CRDs (IngressRoute, IngressRouteTCP, IngressRouteUDP, Middleware, MiddlewareTCP, TraefikService, TLSOption, TLSStore, ServersTransport). |
| Gateway API | pkg/provider/kubernetes/gateway |
gateway.networking.k8s.io and the experimental sub-APIs. |
| Ingress-NGINX shim | pkg/provider/kubernetes/ingress-nginx |
Reads NGINX-flavored Ingress annotations and renders them as Traefik configuration. |
| Knative Serving | pkg/provider/kubernetes/knative |
serving.knative.dev resources. |
The shared client bootstrapping (in-cluster vs out-of-cluster, kubeconfig discovery, namespaces, label-selector filtering) lives in pkg/provider/kubernetes/k8s/.
Ingress
pkg/provider/kubernetes/ingress/ consumes plain Kubernetes Ingress resources. Annotations like traefik.ingress.kubernetes.io/router.entrypoints configure router-level fields that aren't expressible in the standard schema.
A typical Ingress becomes one router (per host/path) and one service (the backend). The provider supports:
IngressClassfiltering — only Ingresses with the configured class are picked up.defaultBackend— emits a router with no rule when set.- TLS — converts Ingress TLS sections to dynamic certificates references.
IngressRoute (CRD)
The CRD provider exposes the full Traefik configuration model directly as Kubernetes resources. Files:
| File | Resource |
|---|---|
ingressroute.go |
IngressRoute, IngressRouteTCP, IngressRouteUDP. |
middleware.go, middlewaretcp.go |
Middleware resources. |
traefikservice.go |
Weighted/mirroring TraefikService resources. |
tlsoption.go, tlsstore.go |
TLS configuration resources. |
serverstransport.go, serverstransporttcp.go |
Upstream transport configuration. |
kubernetes.go |
The provider implementation that watches all of the above. |
IngressRoute's match field carries a Traefik rule directly:
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
spec:
entryPoints: [websecure]
routes:
- match: Host(`api.example.com`) && PathPrefix(`/v1`)
kind: Rule
services:
- name: api
port: 8080
middlewares:
- name: rate-limitGenerated Go types and the typed client live in pkg/provider/kubernetes/crd/generated/. They are produced by script/code-gen.sh (run by make generate-crd).
Gateway API
pkg/provider/kubernetes/gateway/ implements the Gateway API spec. It watches Gateway, GatewayClass, HTTPRoute, TLSRoute, TCPRoute, and GRPCRoute and translates them into Traefik dynamic configuration.
Conformance is enforced by a dedicated CI workflow:
make test-gateway-api-conformanceThe integration test (integration/gateway_api_conformance_test.go) runs the upstream conformance suite against a live Traefik image.
Ingress-NGINX
pkg/provider/kubernetes/ingress-nginx/ reads Ingress resources annotated for the Ingress-NGINX controller and translates the NGINX-specific annotations to Traefik configuration. This is a migration shim: someone moving from Ingress-NGINX to Traefik can keep their existing manifests and have them work, with caveats documented in the official migration guide.
The package shares logic with pkg/middlewares/ingressnginx/ for header/path transformations. The recent commit "Use a metamodel to generate dynamic configuration in ingress-nginx" tightened the translation by introducing a metamodel that disambiguates which annotation maps to which Traefik primitive.
Knative
pkg/provider/kubernetes/knative/ adapts Knative Serving resources (Routes, Configurations, Revisions) into Traefik routers/services. Knative's traffic-splitting between revisions is honored.
The integration test (integration/knative_conformance_test.go) runs the Knative conformance suite via:
make test-knative-conformanceCommon implementation patterns
All five providers share:
- Client construction in
pkg/provider/kubernetes/k8s/client.go. Handles in-cluster, out-of-cluster (kubeconfig), and per-API-group typed clients. - Informer-based caching — providers use
client-goinformers to watch and cache resources. The cache is queried per apply, not per request. - Status reporting —
IngressRouteand Gateway API resources havestatussubresources Traefik updates with the result of applying the route. The status writer is inpkg/provider/kubernetes/crd/kubernetes_dispatch.go(CRD) andpkg/provider/kubernetes/gateway/kubernetes.go(Gateway). - Namespace and label-selector filtering — every provider supports
namespaces:andlabelSelector:static-config fields.
Multi-cluster and federated setups
Each Kubernetes provider has its own endpoint, token, certAuthFilePath settings — you can run multiple instances in the same Traefik configuration to aggregate routes across clusters. The aggregator deduplicates by name/provider, so cross-cluster name collisions need namespacing.
Tests
- Each subpackage has its own
*_test.gocovering fixture-based table tests. integration/k8s_test.goexercises the providers end-to-end against akindestcluster.integration/gateway_api_conformance_test.goandintegration/knative_conformance_test.gorun upstream conformance suites.
Entry points for modification
- A new CRD or annotation: add Go types under
pkg/provider/kubernetes/crd/(or update the relevant translator), regenerate clientsets viamake generate-crd, update conformance fixtures. - Tightening Gateway API behavior: usually a small change in
pkg/provider/kubernetes/gateway/kubernetes.goplus a conformance run. - Migration features for Ingress-NGINX: extend the metamodel under
pkg/provider/kubernetes/ingress-nginx/.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.