Traefik
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
(source https://docs.traefik.io/v1.7/)
Providers
Docker
Following this quickstart: https://docs.traefik.io/v1.7/#the-traefik-quickstart-using-docker Create a docker-compose.yml
services:
reverse-proxy:
image: traefik:v1.7 # The official Traefik docker image
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
whoami:
image: containous/whoami # A container that exposes an API to show its IP address
labels:
- "traefik.frontend.rule=Host:whoami.docker.localhost"
And start traefik as a reverse proxy
You can access the Traefik dashboard already here http://localhost:8080/dashboard/
Start a demo application like this
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
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
Traefik automatically adjusts the routing and does load balancing, so this request goes alternating to one of the endpoints