AlgoViz

Traefik

easy 25 min

Traefik (say "traffic") is a reverse proxy that configures itself.

See it run

A container appears, a request finds it, two rules compete, a certificate arrives and a circuit opens.

Operations

A container appears

Nobody edits a file. The label on the container becomes a route.

Step 1 of 5

Before

Our systemBrowserTraefik1 routerDocker APIblogshop

shop: 404

Only blog is running. A request for the shop gets 404.

Step 1: Before

on(docker_event):    containers = docker.list()    new = {}    for c in containers:        if c.labels.get("traefik.enable") != "true": continue        new[c.rule()] = c.address()    if new != current:        current = new        # no restart
When it happens
Within seconds
Where state lives
Memory, rebuilt

The platform is the configuration.

In the real world

The same traefik doing real jobs. Pick one and step through it.

Why several instances cannot use the built-in ACME together.

Step 1 of 3

Instance 1 orders

Our systemLet's Encryptorder openLoad balancerTraefik 1has tokenTraefik 2no token

Traefik 1 orders a certificate and holds the token.

Step 1: Instance 1 orders

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • The raw Docker socket

    critical

    Who controls a program with full access to the Docker API controls the machine. The documentation calls it a security concern.

    Wrong
    volumes:  - /var/run/docker.sock:/var/run/docker.sock
    Right
    # a socket proxy that only allows reading containers,# on a private network--providers.docker.endpoint=tcp://socket-proxy:2375
  • Everything is public

    critical

    exposedByDefault is true: every container with a port gets a route, the database page too.

    Wrong
    --providers.docker=true
    Right
    --providers.docker=true--providers.docker.exposedbydefault=false
  • acme.json inside the container

    major

    It is lost with the container, and each start orders new certificates until the authority's limit is reached.

    Wrong
    --certificatesresolvers.le.acme.storage=acme.json
    Right
    --certificatesresolvers.le.acme.storage=/data/acme.jsonvolumes: ["le-data:/data"]
  • The open dashboard

    major

    It shows every route and service. The documentation advises against it in production without a login.

    Wrong
    --api.insecure=true
    Right
    --api.dashboard=true# router for api@internal with a login middleware
  • Priority by accident

    minor

    A long regular expression beats a short exact host.

    Wrong
    HostRegexp(`^.+\.test$`)   # longer, so first
    Right
    traefik.http.routers.exact.priority=100

Interview tips

  • How to explain it

    • The proxy asks the platform.
    • Labels become routes.
    • Nobody edits a file.
  • Four words

    • Entry point, router.
    • Middleware, service.
    • Provider: where it all comes from.
  • Reach for it when

    • Containers come and go.
    • A small team runs the edge.
    • Certificates should be automatic.
  • Before production

    • exposedByDefault false.
    • No raw Docker socket.
    • A plan for certificates with two instances.