Open-Source Wikis

/

Traefik

/

Features

/

Providers

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 ProviderName constant. The Docker package exports two (DockerName and SwarmName) since Swarm mode is a separate provider configuration block.
  • exposedByDefault. Most discovery providers default to opting containers/services in. Setting exposedByDefault: false flips the polarity — only items annotated with traefik.enable=true are exposed.
  • Constraints. A constraints expression filters discovered items. Implementation lives in pkg/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/v4 to 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:

  1. Define configuration fields with description, json, yaml, toml tags.
  2. Implement Init() (validation, defaults) and Provide() (the long-running loop).
  3. Register the provider's name and configuration in pkg/config/static/static_config.go.
  4. Add it to pkg/provider/aggregator/aggregator.go so it gets started.
  5. Run make generate to refresh the documentation reference.
  6. 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.

Providers – Traefik wiki | Factory