In this project, we will use:
- Docker
- Docker-Compose
- Traefik LB
- Consul
Traefik is a powerful tool written in GO. This tool has the power to intelligently balance loads. Traefik has 2 ways of configuration: Statics and Dynamics
In this project we will use dynamic, because it's cooler
Consul is a tool also developed in GO by HashiCorp With this tool, we can do a number of things:
- DNS
- Service Mesh
- Service Discovery
- KV Store
In this project we are going to use Consul so that traefik consults the taguiated catalog of services and automatically discovers new hosts to balance the load
First we need to have docker and docker-compose installed on the machine. To install docker and docker-compose run the commands below: Docker:
curl -fsSl https://get.docker.com | sh
Docker-Compose Debian/Ubuntu
apt-get install docker-compose
Red Hat, CentOs
yum install docker-compose
Now... clone the project
git clone https://github.com/matheusmgon/traefik-consul.git
Access the project folder...
Dentro do arquivo "consul/consul-server/config/server.json", existe uma linha que define o DNS que o traefik irá usar para balancear a carga, fica a seu critério alterar, mas lembre-se de colocar em seu arquivo host
To start the project, type:
docker-compose up
Unfortunately using the default Traefik image, the interface will not be accessible, but this we solved by registering a traefik service at the consul.
docker exec -ti traefik curl -XPUT -d '{"ID":"traefik","Name":"traefik","tags":["traefik.enable=true","traefik.http.routers.traefik.entrypoints=web","traefik.http.routers.traefik.rule=Host(`traefik.redelocal`)","traefik.http.routers.traefik.service=api@internal"],"port":80}}' http://consul-server:8500/v1/agent/service/register?replace-existing-checks=true
end ...