Traefik allows you to route incoming URLs to backend systems and those backend systems may be configured automatically by so called Providers, e.g. Docker or Kubernetes




Following this quickstart: Create a docker-compose.yml

version: '3'

    image: traefik:v1.7 # The official Traefik docker image
    command: --api --docker # Enables the web UI and tells Traefik to listen to docker
      - "80:80"     # The HTTP port
      - "8080:8080" # The Web UI (enabled by --api)
      - /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events

    image: containous/whoami # A container that exposes an API to show its IP address
      - "traefik.frontend.rule=Host:whoami.docker.localhost"

And start traefik as a reverse proxy

docker-compose up -d reverse-proxy

You can access the Traefik dashboard already here http://localhost:8080/dashboard/

Start a demo application like this

docker-compose up -d whoami

You should see in here http://localhost:8080/dashboard/ that a public frontend was configured to be connected to an internal backend

You can test the public frontend like this

curl -H Host:whoami.docker.localhost

The curl looks a bit wired. Normally you just need to provide the name, but as it is not a valid DNS name we need to fake the curl request a bit, Traefik needs the request to have the hostname that is configured or it would not reply.

OK, so far, nothing special, you can have set this up with many proxies. But here comes the magic. If you scale the pod to run twice

docker-compose scale whoami=2

Traefik automatically adjusts the routing and does load balancing, so this request goes alternating to one of the endpoints

curl -H Host:whoami.docker.localhost