Creating load-balancing formulas

Now that both our web servers are correctly set up, we can configure our last minion. This minion will be running Nginx in order to balance and proxy requests to our web servers behind the load balancer.

Let's create a directory where we will store all of the states for our load balancer:

[dsala@salt ~]$ sudo mkdir /srv/salt/nginxlb

With the directory created, let's proceed to edit our top.sls file one last time to include the load balancer state file. The top.sls file should look like this:

Before we create our load balancer state file, we will create the Nginx configuration file that we will be pushing to our load balancer VM. Create a file called nginx.conf with the following content:

events { }
http {
upstream webapp {
server web-00:8080;
server web-01:8080;
}
server {
listen 8080;
location / {
proxy_pass http://webapp;
}
}
}

Now, let's proceed to create our final state file. Create a file named lb.sls under the nginxlb directory in /srv/salt/, with the following content:

epel-release:
pkg.installed

nginx:
pkg.installed:
- only_upgrade: False
service.running:
- watch:
- file: /etc/nginx/nginx.conf

/etc/nginx/nginx.conf:
file.managed:
- source: salt://nginxlb/nginx.conf

To apply the final changes, you can run the state.apply command.

Once it's done, you can go ahead and test the load balancer running a cURL to its public IP address:

With this final configuration, we have concluded the proof of concept for Mr. Don High. One very important fact to note is that this example is nowhere near ready for be put into production; this is just an example to show you the basic functionalities and what is possible with Salt Stack.