LoadBalancer as a Service

SWITCHengines offers a LoadBalancer as a Service (LBaaS) that allows you to easily loadbalance (web) traffic to multiple virtual machines. The following is a step by step guide to setting up a simple load balancer via the web interface. It is also possible to do everything with the CLI or scripted. Redhat has a good description of the CLI commands you need to use. 

Preparations

Security Groups

Setup Security Groups for SSH (Port 22) and Web (Port 80 and 443) access if you haven't already done so.

Network

Create a new private subnet with a router (In this example, we use 192.168.0.0/24) but you could use any other network setup.

Web Servers

Setup 2 or 3 virtual machines that have the SSH and Web Security groups and are connected to the newly created network. Assign a floating IP to them in order to install and test them. Connect via SSH and install a web server on them and let it only serve one page with its name (Needless to say, this is for demonstration purposes only)

$ sudo apt-get install apache2
$ sudo sh -c "echo `hostname` > /var/www/html/index.html"

Check that you can connect with your web browser to the instance (it needs a floating IP for this). Once you are done setting up the three servers, you can disassociate the floating IP you needed to set them up.

Loadbalancer

Now that the preparations are done, let's setup load balancing.

Create Pool

Go to the Networks tab in the menu sidebar, and select Loadbalancers. Start by creating a Pool. Give it a name and a description, select the subnet (use the one you created for this example), select the Provider (only haproxy available), the protocol (HTTP) and the Load Balancing Method (use ROUND_ROBIN for now).

Click on Add and you should see that your Pool is active.

Add Members

We now need to add Members to the pool. Go to the Members tab and click Add Member.

Select the pool (web), and the Members (web-1, web-2, web-3), select Weight (1) and the Protocol Port (80 for normal HTTP traffic). Click on Add and you should see 3 active members in the "web" pool.

VIP

As a next step, we need to a a VIP (Virtual IP Address) to the load balancer. Go back to the Pools tab and in the drop down menu for the pool, select Add VIP

Give the VIP a name, and select the previously created network. The assign an arbitrary (but free) IP address from that net to the VIP. Select the protocol and the port. For this example, we don't need Session persistence, but for other use cases you can select an appropriate method. Set the connection limit to -1 (for unlimited connections) and click on Add.

Floating IP

As a final step, we will now assign a floating IP to the VIP. Go to the Compute -> Access and Security Tab and then to the Floating IPs tab. Select a free floating IP and associate it to the VIP.

Testing

Open a web browser and connect to the floating IP Address. You should see the web servers respond.

You can use `curl` to test it from the command line and see that the load balancing actually works:

Monitoring

In order to update the load balancer when web server instances have problems, we can create a Monitor. Go to the Monitors tab. For this example we create a monitor that does HTTP requests to all the members of the pool. It does so every 2 seconds and will disable a member if the check was unsuccessful for 3 times in a row:

Then go to the Pools page, and select Associcate Monitor in the dropdown of your pool and associcate the newly created monitor to the pool.

Now, try to suspend one of your web servers and see what happens: The loadbalancer sets the failed server to Inactive. As soon as the server is back, it will be put back into the load balancers rotation.