Guide: Load Balancers: Difference between revisions

From bwCloud-OS
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
This guide walks through creating a private network, two web server VMs, and exposing them via an OpenStack load balancer. It covers network creation, VM provisioning, floating IP assignment, basic web server setup, and load balancer configuration and testing.
__TOC__
__TOC__


= Guide: Load Balancers =
This guide walks through creating a private network, two web server VMs, and exposing them via an OpenStack load balancer. It covers network creation, VM provisioning, floating IP assignment, basic web server setup, and load balancer configuration and testing.


== Network Setup ==
# Create a private network:


= Network Setup =
== Create a private network: ==
<pre>
<pre>
openstack network create myNet
openstack network create myNet
</pre>
</pre>


# Create a subnet:
== Create a subnet: ==
 
<pre>
<pre>
openstack subnet create mySubNet_v4 --network myNet --subnet-range 192.168.100.0/24
openstack subnet create mySubNet_v4 --network myNet --subnet-range 192.168.100.0/24
</pre>
</pre>


# Create a router and connect it to the public network:
== Create a router and connect it to the public network: ==
 
<pre>
<pre>
openstack router create myRouter
openstack router create myRouter
Line 25: Line 24:
</pre>
</pre>


== Example: Two Webserver as Backend for the Load Balancer ==
= Example: Two Webserver as Backend for the Load Balancer =
 
=== Perpare two Web Server VMs ===
# Create 2 identical VMs as web servers:


== Create 2 identical VMs as web servers: ==
<pre>
<pre>
openstack server create \
openstack server create \
Line 40: Line 37:
</pre>
</pre>


# Assign temporary floating IPs to make the VMs accessible:
== Assign temporary floating IPs to make the VMs accessible: ==
 
<pre>
<pre>
FIP1=$(openstack floating ip create provider_net -f value -c floating_ip_address)
FIP1=$(openstack floating ip create provider_net -f value -c floating_ip_address)
Line 50: Line 46:
</pre>
</pre>


=== Install a basic web server on the VMs ===
== Install a basic web server on the VMs ==
# SSH into each VM and run:
# SSH into each VM and run:


Line 69: Line 65:
</pre>
</pre>


== Integrate the Web Servers with a Load Balancer ==
= Integrate the Web Servers with a Load Balancer =
<span id="loadbalancer-setup"></span>


=== Create a Load Balancer ===
== Create a Load Balancer ==
# Create the load balancer:
# Create the load balancer:


Line 102: Line 97:
</pre>
</pre>


=== Add Web Servers to the Pool ===
== Add Web Servers to the Pool ==
# Get the subnet ID and VM IPs:
# Get the subnet ID and VM IPs:


Line 127: Line 122:
</pre>
</pre>


<span id="loadbalancer-floating-ip"></span>
== Assign a Floating IP to the Load Balancer ==
=== Assign a Floating IP to the Load Balancer ===
 
# Create a floating IP and associate it with the VIP of the load balancer:
# Create a floating IP and associate it with the VIP of the load balancer:



Revision as of 00:01, 26 January 2026

This guide walks through creating a private network, two web server VMs, and exposing them via an OpenStack load balancer. It covers network creation, VM provisioning, floating IP assignment, basic web server setup, and load balancer configuration and testing.


Network Setup

Create a private network:

openstack network create myNet

Create a subnet:

openstack subnet create mySubNet_v4 --network myNet --subnet-range 192.168.100.0/24

Create a router and connect it to the public network:

openstack router create myRouter
openstack router add subnet myRouter mySubNet_v4
openstack router set myRouter --external-gateway provider_net

Example: Two Webserver as Backend for the Load Balancer

Create 2 identical VMs as web servers:

openstack server create \
  --image ubuntu-24.04 \
  --flavor m1.small \
  --network myNet \
  --key-name myKey \
  --min 2 --max 2 \
  webserver

Assign temporary floating IPs to make the VMs accessible:

FIP1=$(openstack floating ip create provider_net -f value -c floating_ip_address)
FIP2=$(openstack floating ip create provider_net -f value -c floating_ip_address)

openstack server add floating ip webserver-1 $FIP1
openstack server add floating ip webserver-2 $FIP2

Install a basic web server on the VMs

  1. SSH into each VM and run:
sudo apt update && \
sudo apt -y install apache2 && \
sudo systemctl enable --now apache2 && \
echo webserver-1 | sudo tee /var/www/html/index.html
  1. Add security rules to allow HTTP access on port 80 as described in the Security section.
  1. Test the web servers:
curl $FIP1
# Expected output: webserver-1

Integrate the Web Servers with a Load Balancer

Create a Load Balancer

  1. Create the load balancer:
openstack loadbalancer create \
  --name myLB \
  --vip-subnet-id mySubNet_v4 \
  --provider ovn
  1. Create a listener on port 80:
openstack loadbalancer listener create \
    --name myListener \
    --protocol TCP \
    --protocol-port 80 \
    myLB
  1. Create a pool for the listener:
openstack loadbalancer pool create \
    --name myPool \
    --listener myListener \
    --protocol TCP \
    --lb-algorithm SOURCE_IP_PORT

Add Web Servers to the Pool

  1. Get the subnet ID and VM IPs:
SUBNET_ID=$(openstack subnet list --network myNet -f value -c ID)
WEB1_IP=$(openstack server show webserver-1 -f value -c addresses | grep -o '192\.168\.100\.[0-9]\+')
WEB2_IP=$(openstack server show webserver-2 -f value -c addresses | grep -o '192\.168\.100\.[0-9]\+')
  1. Add each VM to the pool:
openstack loadbalancer member create \
    --subnet-id $SUBNET_ID \
    --address $WEB1_IP \
    --protocol-port 80 \
    myPool

openstack loadbalancer member create \
    --subnet-id $SUBNET_ID \
    --address $WEB2_IP \
    --protocol-port 80 \
    myPool

Assign a Floating IP to the Load Balancer

  1. Create a floating IP and associate it with the VIP of the load balancer:
FIP=$(openstack floating ip create provider_net -f value -c floating_ip_address)
VIPPORT=$(openstack loadbalancer show myLB -f value -c vip_port_id)
openstack floating ip set --port $VIPPORT $FIP
  1. Test the load balancer:
curl $FIP
# Expected output (may alternate between VMs): webserver-1 / webserver-2