Træfik ( pronounced like traffic ) is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease. It supports respective backends ( Docker, Swarm, Mesos/Marathon, Consul, Etcd, Zookeeper, BoltDB, Amazon ECS, Amazon DynamoDB, Rest API, charge … ) to manage its configuration mechanically and dynamically .
imagine that you have deployed a bunch of microservices on your infrastructure. You credibly used a avail register ( like etcd or consul ) and/or an orchestrator ( drove, Mesos/Marathon ) to manage all these services. If you want your users to access some of your microservices from the Internet, you will have to use a overrule proxy and configure it using virtual hosts or prefix paths :
Reading: Træfik | Traefik | v1.3
api.domain.comwill point the microservice
apiin your private network
domain.com/webwill point the microservice
webin your private network
backoffice.domain.comwill point the microservices
backofficein your private network, load-balancing between your multiple instances
But a microservices architecture is dynamic … Services are added, removed, killed or upgrade much, finally several times a day .
traditional reverse-proxies are not natively dynamic. You ca n’t change their configuration and hot-reload easily .
here enters Træfik .
Træfik can listen to your service registry/orchestrator API, and knows each clock time a microservice is added, removed, killed or upgrade, and can generate its configuration mechanically. Routes to your services will be created instantaneously .
Run it and forget it !
You can have a quick expect at Træfik in this Katacoda tutorial that shows how to load balance requests between multiple Docker containers .
here is a spill given by Ed Robinson at the ContainerCamp UK conference. You will learn cardinal Træfik features and see some demos with Kubernetes.
here is a spill the beans ( in French ) given by Emile Vauge at the Devoxx France 2016 conference. You will learn fundamental Træfik features and see some demos with Docker, Mesos/Marathon and Let ‘s Encrypt .
You can grab the latest binary from the releases page and barely run it with the sample distribution configuration file :
./traefik -c traefik.toml
Using the bantam Docker image :
docker run -d -p 8080:8080 -p 80:80 -v $PWD/traefik.toml:/etc/traefik/traefik.toml traefik
You can test Træfik well using Docker compose, with this
docker-compose.yml file in a folder named
version: '2' services: proxy: image: traefik command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG networks: - webgateway ports: - "80:80" - "8080:8080" volumes: - /var/run/docker.sock:/var/run/docker.sock - /dev/null:/traefik.toml networks: webgateway: driver: bridge
Start it from within the
traefik booklet :
docker-compose up -d
In a browser you may open
http://localhost:8080 to access Træfik ‘s splashboard and observe the stick to magic.
now, create a folder named
test and create a
docker-compose.yml in it with this contentedness :
version: '2' services: whoami: image: emilevauge/whoami networks: - web labels: - "traefik.backend=whoami" - "traefik.frontend.rule=Host:whoami.docker.localhost" networks: web: external: name: traefik_webgateway
then, start and scale it in the
test booklet :
docker-compose up -d docker-compose scale whoami=2
last, test load-balancing between the two services
$ curl -H Host:whoami.docker.localhost http://127.0.0.1 Hostname: ef194d07634a IP: 127.0.0.1 IP: ::1 IP: 172.17.0.4 IP: fe80::42:acff:fe11:4 GET / HTTP/1.1 Host: 172.17.0.4:80 User-Agent: curl/7.35.0 Accept: */* Accept-Encoding: gzip X-Forwarded-For: 172.17.0.1 X-Forwarded-Host: 172.17.0.4:80 X-Forwarded-Proto: http X-Forwarded-Server: dbb60406010d $ curl -H Host:whoami.docker.localhost http://127.0.0.1 Hostname: 6c3c5df0c79a IP: 127.0.0.1 IP: ::1 IP: 172.17.0.3 IP: fe80::42:acff:fe11:3 GET / HTTP/1.1 Host: 172.17.0.3:80 User-Agent: curl/7.35.0 Accept: */* Accept-Encoding: gzip X-Forwarded-For: 172.17.0.1 X-Forwarded-Host: 172.17.0.3:80 X-Forwarded-Proto: http X-Forwarded-Server: dbb60406010d