Dockerized Load Balancer Implementation

Load balancing architecture is to increase the availability and reliability of applications, so if a certain number of clients request some number of resources to backends, Load balancer stays between them and route the traffic to the backend

To setup Nginx as a load balancer (Containerized As well As Bare host LB) for backend servers, follow these steps:

  1. Open the Nginx configuration file with elevated rights
  2. Define an upstream element and list each node in your backend cluster
  3. Map a URI to the upstream cluster with a proxy_pass location setting
  4. Restart the Nginx server to incorporate the config changes
  5. Verify successful configuration of the Nginx load balancer setup

As your Nginx configuration grows, this will require changes to the file in which the upstream element and the proxy_pass location setting must be configured.

For this Containerized load balancer example, we will edit the file named default which is mounted in the container /etc/nginx/conf.d/default.conf directory.

./web1/Dockerfile

./web1/index.html

./web2/Dockerfile

./web2/index.html

./nginx/Dockerfile

./nginx/nginx.conf

docker-compose.yml

Now run the following command and type the url on the browser to check connectivity (http://loadbalancer)

You may also find the complete code on the below Github repo:

***************************************************

For this Nginx load balancer (S/w LB) example, we will edit the file named default which is in the /etc/nginx/sites-available/default folder.

Enjoy!!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store