Load balancing is crucial for distributing traffic across multiple instances. Our OpenStack environment uses the Amphora provider for load balancing services.

Overview

Amphora is a provider driver for OpenStack’s Octavia project. It deploys virtual machines (amphora instances) to handle load balancing tasks.

Creating a Load Balancer

Step 1: Create the Load Balancer

openstack loadbalancer create --name <lb-name> --vip-subnet-id <subnet-id> --provider amphora

Example:

openstack loadbalancer create --name my-lb --vip-subnet-id private-subnet --provider amphora

Wait for the load balancer to become ACTIVE before proceeding. You can check the status with:

openstack loadbalancer show my-lb

Step 2: Create a Listener

The listener defines the protocol and port for incoming traffic.

openstack loadbalancer listener create --name <listener-name> --protocol HTTP --protocol-port 80 <lb-name>

Example:

openstack loadbalancer listener create --name my-listener --protocol HTTP --protocol-port 80 my-lb

Step 3: Create a Pool

The pool is a group of backend members that will receive the traffic.

openstack loadbalancer pool create --name <pool-name> --lb-algorithm ROUND_ROBIN --listener <listener-name> --protocol HTTP

Example:

openstack loadbalancer pool create --name my-pool --lb-algorithm ROUND_ROBIN --listener my-listener --protocol HTTP

Step 4: Add Members to the Pool

Add your instances to the pool. You need the IP address of each instance and the port they are listening on.

openstack loadbalancer member create --subnet-id <subnet-id> --address <instance-ip> --protocol-port 80 <pool-name>

Example:

openstack loadbalancer member create --subnet-id private-subnet --address 192.168.0.10 --protocol-port 80 my-pool
openstack loadbalancer member create --subnet-id private-subnet --address 192.168.0.11 --protocol-port 80 my-pool

Step 5: Create a Health Monitor

Configure a health monitor to check the status of your backend members.

openstack loadbalancer healthmonitor create --delay 5 --max-retries 4 --timeout 10 --type HTTP --url-path / <pool-name>

Example:

openstack loadbalancer healthmonitor create --delay 5 --max-retries 4 --timeout 10 --type HTTP --url-path / my-pool

Floating IP

To make your load balancer accessible from the internet, assign a floating IP to its Virtual IP (VIP).

  1. Get the VIP port ID:

    openstack loadbalancer show my-lb -c vip_port_id -f value
  2. Create a floating IP and associate it with the VIP port:

    openstack floating ip create public --port <vip-port-id>

Best Practices

  • Security Groups: Ensure your security groups allow traffic from the load balancer to your instances.
  • Monitoring: Regularly check the status of your load balancer and backend instances using openstack loadbalancer status show <lb-name>.