Create an Openstack LB

This guide shows how to create and use an Openstack LB. We will create two VMs, a LB that will balance the load between these two VMs, and will test the LB with curl.

Create the VMs

Create two VMs in your Openstack project through the Dashboard or CLI. Name it, for example, test-vm-1 and test-vm-2.

Create a new security group that enables network traffic on port 80 and associate it to the VMs.

Create and associate a floating IP to each VM.

Run a simple web server

On test-vm-1:

  1. ssh ubuntu@<floating-ip-srv1>
  2. vim index.html -> <html>This is SERVER 1</html>
  3. sudo python3 -m http.server 80 &> /dev/null &

On test-vm-2:

  1. ssh ubuntu@<floating-ip-srv1>
  2. vim index.html -> <html>This is SERVER 2</html>
  3. sudo python3 -m http.server 80 &> /dev/null &

Create a new LB

  1. openstack loadbalancer create --name test-lb --vip-subnet-id <subnet-id>
  2. openstack loadbalancer listener create --name test-listener --protocol HTTP --protocol-port 80 test-lb
  3. openstack loadbalancer pool create --name test-pool --lb-algorithm ROUND_ROBIN --listener test-listener --protocol HTTP
  4. openstack loadbalancer member create --subnet-id <subnet-id> --address <test-vm-1-private-ip> --protocol-port 80 test-pool
  5. openstack loadbalancer member create --subnet-id <subnet-id> --address <test-vm-2-private-ip> --protocol-port 80 test-pool
  6. Get the loadbalancer vip port (vip_port_id) -> openstack loadbalancer show test-lb
  7. Create a new floating ip through the Openstack Dashboard or CLI
  8. Associate the previous floating ip to the LB vip port-> openstack floating ip set --port <vip-port-id> <floating-ip>

Note: now it is possibile to remove the floating ips from the two VMs.

Test the LB

curl <LB-floating-ip>