traefik/traefik
Providers
A provider is the source of dynamic configuration. Each provider is its own subpackage under pkg/provider/. They all implement a small interface in pkg/provider/provider.go:
type Provider interface {
Init() error
Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error
}Provide is expected to run forever (or until the routines pool is stopped) and emit dynamic.Message values whenever the source produces a new configuration.
Built-in providers
| Provider | Package | Best for |
|---|---|---|
| File / Directory | pkg/provider/file |
Static or hand-edited configurations. |
| Docker / Swarm | pkg/provider/docker |
Single-host Docker, Docker Compose, Swarm mode. |
| Kubernetes Ingress | pkg/provider/kubernetes/ingress |
Standard Kubernetes Ingress resources. |
| Kubernetes IngressRoute (CRD) | pkg/provider/kubernetes/crd |
Traefik-specific Kubernetes CRDs. |
| Kubernetes Gateway API | pkg/provider/kubernetes/gateway |
Gateway API standard. |
| Kubernetes Ingress-NGINX shim | pkg/provider/kubernetes/ingress-nginx |
Migration from the Ingress-NGINX controller. |
| Knative Serving | pkg/provider/kubernetes/knative |
Knative-managed routes. |
| Consul (KV) | pkg/provider/kv/consul |
Consul KV. |
| etcd | pkg/provider/kv/etcd |
etcd KV. |
| Redis | pkg/provider/kv/redis |
Redis hash-based configuration. |
| ZooKeeper | pkg/provider/kv/zk |
ZooKeeper KV. |
| Consul Catalog | pkg/provider/consulcatalog |
Consul service registry. |
| Nomad | pkg/provider/nomad |
Nomad job catalog. |
| Amazon ECS | pkg/provider/ecs |
ECS task definitions. |
| HTTP | pkg/provider/http |
Pull configuration from a URL. |
| REST | pkg/provider/rest |
Push configuration to Traefik's API. |
| Tailscale | pkg/provider/tailscale |
Tailscale-issued certificates. |
| ACME | pkg/provider/acme |
Automatic Let's Encrypt certificates. |
| Internal | pkg/provider/traefik |
Built-in routes for the dashboard / ping / Prometheus. |
How providers register themselves
pkg/config/static/static_config.go declares a fixed precedence list:
var providerNames = []string{
gateway.ProviderName,
crd.ProviderName,
ingress.ProviderName,
ingressnginx.ProviderName,
docker.SwarmName,
docker.DockerName,
file.ProviderName,
redis.ProviderName,
knative.ProviderName,
consul.ProviderName,
consulcatalog.ProviderName,
nomad.ProviderName,
etcd.ProviderName,
ecs.ProviderName,
http.ProviderName,
zk.ProviderName,
rest.ProviderName,
}This is the order in which providers are wrapped by the aggregator (pkg/provider/aggregator/aggregator.go) and the order used as the tie-breaker when an object name appears in multiple providers.
Any provider that is not enabled in static config is simply not constructed.
Conventions across providers
- Name constant. Each provider exports a
ProviderNameconstant. The Docker package exports two (DockerNameandSwarmName) since Swarm mode is a separate provider configuration block. exposedByDefault. Most discovery providers default to opting containers/services in. SettingexposedByDefault: falseflips the polarity — only items annotated withtraefik.enable=trueare exposed.- Constraints. A
constraintsexpression filters discovered items. Implementation lives inpkg/provider/constraints/. - Default rule. Each provider can produce a router rule from a Go template if no rule was supplied. Default rules use template variables like
{{ .Name }},{{ index .Labels "namespace" }}. - Reconnection. Watch-style providers (Kubernetes, Docker events, Consul watch) use
cenkalti/backoff/v4to reconnect indefinitely on failure.
Anatomy of a provider
A typical provider has these files:
| File | Role |
|---|---|
<provider>.go |
The Provider struct, configuration fields, Init() and Provide() implementation. |
config.go |
The mapping from labels/annotations/CRDs to dynamic.Configuration. |
data.go (Docker) / client.go (Kubernetes) |
The interface to the upstream API, mockable for tests. |
<provider>_test.go |
Unit tests, often using a fixture file. |
fixtures/... |
Recorded API responses for table-driven tests. |
Adding a provider is mostly:
- Define configuration fields with
description,json,yaml,tomltags. - Implement
Init()(validation, defaults) andProvide()(the long-running loop). - Register the provider's name and configuration in
pkg/config/static/static_config.go. - Add it to
pkg/provider/aggregator/aggregator.goso it gets started. - Run
make generateto refresh the documentation reference. - Add an integration test in
integration/<name>_test.go.
The provider pages below cover the larger or more frequently asked-about ones in more detail.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.