DevOps
Traefik
Traefik is a cloud-native reverse proxy and edge router that discovers services in Docker and Kubernetes and configures routes itself.
What it is
Traefik was created by Emile Vauge (Traefik Labs) and first released in 2015. It is a reverse proxy and load balancer built for microservices: it connects to providers (Docker, Kubernetes, Consul, files) and builds routes itself as services appear or disappear.
Routes are set by labels on containers or Kubernetes resources (Ingress, IngressRoute). Core concepts: entrypoints (ports Traefik listens on), routers (rules by host and path), middlewares (redirects, auth, rate limit) and services.
Traefik can get Let's Encrypt certificates automatically, has a built-in dashboard and is widely used as an ingress controller in Kubernetes.
Use it when
- You have many containers that appear and disappear dynamically.
- You need an ingress controller for Kubernetes.
- You want to manage routes through labels in Docker Compose.
Avoid it when
- A simple static site or one app: Caddy or nginx are simpler.
- You need deep tuning of caching and static serving: nginx is stronger.
Key concepts
- Provider
- A source of configuration and service discovery: Docker, Kubernetes, a file.
- Entrypoint
- A port and protocol Traefik listens on (for example web on 80, websecure on 443).
- Router
- A rule that ties a request (Host, PathPrefix) to a service.
- Middleware
- An intermediate processing step: redirect, basic auth, rate limit, compression.
Example
Interview questions
1. What is Traefik's main idea?
Dynamic configuration: it reads from Docker or Kubernetes which services exist and builds routes itself. No manual config edits and proxy restarts on every deploy.
2. What are a router, a service and a middleware?
A router defines the matching rule for a request, a service describes the backend to forward to, and a middleware is a step on the way, such as a redirect or authentication.
3. Traefik or nginx?
Traefik is better in dynamic container environments with auto discovery and certificates. nginx is stronger at static serving, caching and fine tuning, but its config is static.
Related technologies
- nginxnginx is a fast web server and reverse proxy that also works as a load balancer and HTTP cache.
- CaddyCaddy is a web server and reverse proxy written in Go with automatic HTTPS and very simple configuration.
- KubernetesKubernetes is a container orchestration system that deploys, scales and heals applications across a cluster of servers.
- DockerDocker packages an application with its dependencies into a container that runs the same on a laptop, a server and the cloud.
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).