Traefik
easy 25 minTraefik (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
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
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
criticalWho controls a program with full access to the Docker API controls the machine. The documentation calls it a security concern.
Wrongvolumes: - /var/run/docker.sock:/var/run/docker.sockRight# a socket proxy that only allows reading containers,# on a private network--providers.docker.endpoint=tcp://socket-proxy:2375Everything is public
criticalexposedByDefault is true: every container with a port gets a route, the database page too.
Wrong--providers.docker=trueRight--providers.docker=true--providers.docker.exposedbydefault=falseacme.json inside the container
majorIt is lost with the container, and each start orders new certificates until the authority's limit is reached.
Wrong--certificatesresolvers.le.acme.storage=acme.jsonRight--certificatesresolvers.le.acme.storage=/data/acme.jsonvolumes: ["le-data:/data"]The open dashboard
majorIt shows every route and service. The documentation advises against it in production without a login.
Wrong--api.insecure=trueRight--api.dashboard=true# router for api@internal with a login middlewarePriority by accident
minorA long regular expression beats a short exact host.
WrongHostRegexp(`^.+\.test$`) # longer, so firstRighttraefik.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.