Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Latest commit

 

History

History
73 lines (39 loc) · 3.03 KB

README.md

File metadata and controls

73 lines (39 loc) · 3.03 KB

How to setup Nginx as a dynamic load balancer ?

The following application demonstrate how to setup a dynamic load balancing with :

How to use ?

First of all you have to install Consul and Consul UI.

Then you have to start Consul as an agent server on the docker host.

consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -ui-dir /usr/local/share/consul --client 0.0.0.0

Then you can start the services :

docker-compose up 

This should start all services defined in docker-compose.yml.

The sample app should be running and being available at http://localhost/, displaying the hostname of the container serving the application.

Now we want to scale up the sample application :

docker-compose scale app=5

and we can see refreshing the sample app in your favorite browser, the hostname should change.

If you check the Consul UI located at http://localhost:8500/ui, you you should see 5 instances of the sample application (named app).

Now we can scale down the sample application :

docker-compose scale app=1

and the containers should be stopped and destroyed.

How it works ?

The registrator container is responsable for registering and deregistering services based on container start and die events from Docker.

The consul container maintain the service registry.

The nginx use S6 as system init to run nginx and consul-template in the same container.

The role of consul-template is to generate a valid nginx configuration file in /etc/nginx/conf.d directory based on a template and reload Nginx when new services are registered in Consul.

Thanks

We would like to thanks :