Guide: Load Balancers: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
This guide walks through creating a private network, two web server VMs, and exposing them via an OpenStack load balancer. | This guide walks through creating a private network, deploying two web server VMs on it, and exposing them via an OpenStack load balancer to a public network. | ||
| Line 52: | Line 52: | ||
sudo systemctl enable --now apache2 && \ | sudo systemctl enable --now apache2 && \ | ||
echo $(hostname) | sudo tee /var/www/html/index.html | echo $(hostname) | sudo tee /var/www/html/index.html | ||
</pre>Add security rules to allow HTTP access on port 80 as described in the section on [[Security#Example: Opening Port 443 for HTTPS Access|Security Rules.]] | </pre>Add security rules to both VMs to allow HTTP access on port 80 as described in the section on [[Security#Example: Opening Port 443 for HTTPS Access|Security Rules.]] | ||
| Line 114: | Line 114: | ||
VIPPORT=$(openstack loadbalancer show myLB -f value -c vip_port_id) | VIPPORT=$(openstack loadbalancer show myLB -f value -c vip_port_id) | ||
openstack floating ip set --port $VIPPORT $FIP | openstack floating ip set --port $VIPPORT $FIP | ||
</pre>Test the load balancer:<pre> | </pre> | ||
Test the load balancer: | |||
<pre> | |||
curl $FIP | curl $FIP | ||
# Expected output (may alternate between VMs): webserver-1 / webserver-2 | # Expected output (may alternate between VMs): webserver-1 / webserver-2 | ||
</pre> | </pre> | ||
Latest revision as of 12:30, 26 January 2026
This guide walks through creating a private network, deploying two web server VMs on it, and exposing them via an OpenStack load balancer to a public network.
Network Setup
Create a private network
openstack network create myNet
Create a subnet of the private network
openstack subnet create myNet_v4 --network myNet --subnet-range 192.168.100.0/24
Create a router and connect it to a public network
openstack router create myRouter openstack router add subnet myRouter myNet_v4 openstack router set myRouter --external-gateway provider_net
Creating Backend Instances for Load Balancing
As an example, we create two identical web server instances that will serve as backend nodes for the load balancer.
Create two identical VMs
openstack server create \ --image ubuntu-24.04 \ --flavor m1.small \ --network myNet \ --key-name myKey \ --min 2 --max 2 \ webserver
Associate (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 basic web servers on the VMs
SSH into each VM and run:
sudo apt update && \ sudo apt -y install apache2 && \ sudo systemctl enable --now apache2 && \ echo $(hostname) | sudo tee /var/www/html/index.html
Add security rules to both VMs to allow HTTP access on port 80 as described in the section on Security Rules.
Test the web servers:
curl $FIP1 # Expected output: webserver-1
Load Balancer Setup and Backend Integration
Create the load balancer
openstack loadbalancer create \ --name myLB \ --vip-subnet-id myNet_v4 \ --provider ovn
Create a listener on port 80
openstack loadbalancer listener create \
--name myListener \
--protocol TCP \
--protocol-port 80 \
myLB
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
Get the subnet ID and VM IPs in it:
SUBNET_ID=$(openstack subnet list --name myNet_v4 -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]\+')
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
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
Test the load balancer:
curl $FIP # Expected output (may alternate between VMs): webserver-1 / webserver-2