Blog
Search…
Load balancer as a service OpenStack LbaaS
The following guide will show you how to deploy a LoadBalancer in Openstack with Neutron, but first, you should understand how it works, and what his components do.
A Load Balancer is composed of the following components:
  • Pool - A pool is a group of servers(members) who are designed to make
    the same job, generally, a pool of web servers is used for balancing
    traffic between the members of the pool. Here we will configure the
    Load Balancing Method (ROUND_ROBIN,LEAST_CONNECTIONS,SOURCE_IP)
  • Members - Members are instances, a server, any aplication that you
    can balance the load. They are assigned as pool members.
  • VIP - VIPs are Virtual IPs that logically represents the pool
    members. It is the IP where the load will be balanced between
    instances.
  • Healthmonitor - Healthmonitor will check if the members of a pool are
    healthy, if an member is not working or the port/protocol monitored
    is down, healthmonitor will send a message to the pool to not balance
    the load to this member.
Now will create a Pool with 2 members, this Pool have a VIP and a Healthmonitor on it.
First we create a Pool
1
[[email protected] devstack]$ neutron lb-pool-create --lb-method ROUND_ROBIN --name LoadBalancerPool --protocol HTTP --subnet-id e5a90ab2-918e-412b-9723-0d822804f022
2
Created a new pool:
3
+------------------------+--------------------------------------+
4
| Field                  | Value                                |
5
+------------------------+--------------------------------------+
6
| admin_state_up         | True                                 |
7
| description            |                                      |
8
| health_monitors        |                                      |
9
| health_monitors_status |                                      |
10
| id                     | 3eb0d41c-3df5-4beb-9758-ebfef56909df |
11
| lb_method              | ROUND_ROBIN                          |
12
| members                |                                      |
13
| name                   | LoadBalancerPool                     |
14
| protocol               | HTTP                                 |
15
| provider               | haproxy                              |
16
| status                 | PENDING_CREATE                       |
17
| status_description     |                                      |
18
| subnet_id              | e5a90ab2-918e-412b-9723-0d822804f022 |
19
| tenant_id              | b1aaddea9f694e60aea5f1c0d1dd7c24     |
20
| vip_id                 |                                      |
21
+------------------------+--------------------------------------+
Copied!
Next boot 2 instances in the same network
1
[[email protected] devstack]$ nova boot --flavor m1.tiny --image 6a3a7880-bc6f-454d-9a62-d9c2d268ef78 --security-groups default --nic net-id=daddce32-b6e8-4e3f-bd55-32459ed327ea WebServer1
2
[[email protected] devstack]$ nova boot --flavor m1.tiny --image 6a3a7880-bc6f-454d-9a62-d9c2d268ef78 --security-groups default --nic net-id=daddce32-b6e8-4e3f-bd55-32459ed327ea WebServer2
3
4
[[email protected] devstack]$ nova list
5
+--------------------------------------+------------+--------+------------+-------------+------------------+
6
| ID                                   | Name       | Status | Task State | Power State | Networks         |
7
+--------------------------------------+------------+--------+------------+-------------+------------------+
8
| c10e63c6-f342-4d1c-ae22-146c392ce398 | WebServer1 | BUILD  | spawning   | NOSTATE     | private=10.0.0.3 |
9
| ceef9e6b-6198-4118-8027-00898dee1abe | WebServer2 | BUILD  | spawning   | NOSTATE     | private=10.0.0.4 |
10
+--------------------------------------+------------+--------+------------+-------------+------------------+
Copied!
Assign both instances to the Pool
1
[[email protected] devstack]$ neutron lb-member-create --address 10.0.0.3 --protocol-port 80 LoadBalancerPool
2
Created a new member:
3
+--------------------+--------------------------------------+
4
| Field              | Value                                |
5
+--------------------+--------------------------------------+
6
| address            | 10.0.0.3                             |
7
| admin_state_up     | True                                 |
8
| id                 | a6de6bf0-3191-4721-aa01-5781ff05876e |
9
| pool_id            | 3eb0d41c-3df5-4beb-9758-ebfef56909df |
10
| protocol_port      | 80                                   |
11
| status             | PENDING_CREATE                       |
12
| status_description |                                      |
13
| tenant_id          | b1aaddea9f694e60aea5f1c0d1dd7c24     |
14
| weight             | 1                                    |
15
+--------------------+--------------------------------------+
16
17
[[email protected] devstack]$ neutron lb-member-create --address 10.0.0.4 --protocol-port 80 LoadBalancerPool
18
Created a new member:
19
+--------------------+--------------------------------------+
20
| Field              | Value                                |
21
+--------------------+--------------------------------------+
22
| address            | 10.0.0.4                             |
23
| admin_state_up     | True                                 |
24
| id                 | 9688a770-6494-4599-88fa-6afcd18c4dd1 |
25
| pool_id            | 3eb0d41c-3df5-4beb-9758-ebfef56909df |
26
| protocol_port      | 80                                   |
27
| status             | PENDING_CREATE                       |
28
| status_description |                                      |
29
| tenant_id          | b1aaddea9f694e60aea5f1c0d1dd7c24     |
30
| weight             | 1                                    |
31
+--------------------+--------------------------------------+
Copied!
Then create a Healthmonitor and associate it to the Pool
1
[[email protected] devstack]$ neutron lb-healthmonitor-create --timeout 3 --max-retries 3 --delay 60 --type HTTP
2
Created a new health_monitor:
3
+----------------+--------------------------------------+
4
| Field          | Value                                |
5
+----------------+--------------------------------------+
6
| admin_state_up | True                                 |
7
| delay          | 60                                   |
8
| expected_codes | 200                                  |
9
| http_method    | GET                                  |
10
| id             | cb73f8fd-14ea-4937-aa10-019e3da8432f |
11
| max_retries    | 3                                    |
12
| pools          |                                      |
13
| tenant_id      | b1aaddea9f694e60aea5f1c0d1dd7c24     |
14
| timeout        | 3                                    |
15
| type           | HTTP                                 |
16
| url_path       | /                                    |
17
+----------------+--------------------------------------+
18
[[email protected] devstack]$ neutron lb-healthmonitor-associate cb73f8fd-14ea-4937-aa10-019e3da8432f LoadBalancerPool
19
Associated health monitor cb73f8fd-14ea-4937-aa10-019e3da8432f
Copied!
Create a VIP to the Pool
1
[[email protected] devstack]$ neutron lb-vip-create --name LoadBalancerVIP --protocol-port 80 --protocol HTTP --subnet-id e5a90ab2-918e-412b-9723-0d822804f022 LoadBalancerPool
2
Created a new vip:
3
+---------------------+--------------------------------------+
4
| Field               | Value                                |
5
+---------------------+--------------------------------------+
6
| address             | 10.0.0.5                             |
7
| admin_state_up      | True                                 |
8
| connection_limit    | -1                                   |
9
| description         |                                      |
10
| id                  | 4e3c2b84-a286-4999-a258-51c44965a81a |
11
| name                | LoadBalancerVIP                      |
12
| pool_id             | 3eb0d41c-3df5-4beb-9758-ebfef56909df |
13
| port_id             | d4ed46ac-aabf-40b6-8f28-1a2013971391 |
14
| protocol            | HTTP                                 |
15
| protocol_port       | 80                                   |
16
| session_persistence |                                      |
17
| status              | PENDING_CREATE                       |
18
| status_description  |                                      |
19
| subnet_id           | e5a90ab2-918e-412b-9723-0d822804f022 |
20
| tenant_id           | b1aaddea9f694e60aea5f1c0d1dd7c24     |
21
+---------------------+--------------------------------------+
Copied!
Create a floating IP to the VIP
1
[[email protected] devstack]$ neutron floatingip-create 23101147-e724-4574-82c7-a05ccb661d4d
2
Created a new floatingip:
3
+---------------------+--------------------------------------+
4
| Field               | Value                                |
5
+---------------------+--------------------------------------+
6
| fixed_ip_address    |                                      |
7
| floating_ip_address | 172.24.4.3                           |
8
| floating_network_id | 23101147-e724-4574-82c7-a05ccb661d4d |
9
| id                  | 62fbf609-77db-4471-b6ae-9fe25a091a21 |
10
| port_id             |                                      |
11
| router_id           |                                      |
12
| status              | DOWN                                 |
13
| tenant_id           | b1aaddea9f694e60aea5f1c0d1dd7c24     |
14
+---------------------+--------------------------------------+
Copied!
Associate the floating IP with the VIP port
1
[[email protected] devstack]$ neutron floatingip-associate 62fbf609-77db-4471-b6ae-9fe25a091a21 d4ed46ac-aabf-40b6-8f28-1a2013971391
2
Associated floating IP 62fbf609-77db-4471-b6ae-9fe25a091a21
Copied!
Create security rules to allow HTTP, SSH and ICMP traffic
1
[[email protected] devstack]$ neutron security-group-rule-create --protocol TCP --port-range-min 80 --port-range-max 80 be0b2264-744a-48b8-9a1e-033227d78f2b
2
Created a new security_group_rule:
3
+-------------------+--------------------------------------+
4
| Field             | Value                                |
5
+-------------------+--------------------------------------+
6
| direction         | ingress                              |
7
| ethertype         | IPv4                                 |
8
| id                | 4635cbb6-d939-40b3-ac11-637c8b63b027 |
9
| port_range_max    | 80                                   |
10
| port_range_min    | 80                                   |
11
| protocol          | tcp                                  |
12
| remote_group_id   |                                      |
13
| remote_ip_prefix  |                                      |
14
| security_group_id | be0b2264-744a-48b8-9a1e-033227d78f2b |
15
| tenant_id         | b1aaddea9f694e60aea5f1c0d1dd7c24     |
16
+-------------------+--------------------------------------+
17
18
[[email protected] devstack]$ neutron security-group-rule-create --protocol icmp be0b2264-744a-48b8-9a1e-033227d78f2b
19
Created a new security_group_rule:
20
+-------------------+--------------------------------------+
21
| Field             | Value                                |
22
+-------------------+--------------------------------------+
23
| direction         | ingress                              |
24
| ethertype         | IPv4                                 |
25
| id                | 988329a1-d686-4541-8950-a22c721f847b |
26
| port_range_max    |                                      |
27
| port_range_min    |                                      |
28
| protocol          | icmp                                 |
29
| remote_group_id   |                                      |
30
| remote_ip_prefix  |                                      |
31
| security_group_id | be0b2264-744a-48b8-9a1e-033227d78f2b |
32
| tenant_id         | b1aaddea9f694e60aea5f1c0d1dd7c24     |
33
+-------------------+--------------------------------------+
34
35
[[email protected] devstack]$ neutron security-group-rule-create --protocol TCP --port-range-min 22 --port-range-max 22 be0b2264-744a-48b8-9a1e-033227d78f2b
36
Created a new security_group_rule:
37
+-------------------+--------------------------------------+
38
| Field             | Value                                |
39
+-------------------+--------------------------------------+
40
| direction         | ingress                              |
41
| ethertype         | IPv4                                 |
42
| id                | d18724dc-2eda-4031-be88-202a73c30c24 |
43
| port_range_max    | 22                                   |
44
| port_range_min    | 22                                   |
45
| protocol          | tcp                                  |
46
| remote_group_id   |                                      |
47
| remote_ip_pref                          |
48
| security_group_id | d7412bb3-9824-4eb7-bc4b-cd80ab6a570d |
49
| tenant_id         | b1aaddea9f694e60aea5f1c0d1dd7c24     |
50
+-------------------+--------------------------------------+
Copied!
Login to both instances and run the command below to run a "webserver".
1
[[email protected]ocalhost devstack]$ ssh [email protected]
2
The authenticity of host '10.0.0.3 (10.0.0.3)' can't be established.
3
RSA key fingerprint is 94:00:8e:fe:9a:9d:af:ef:bc:e3:fd:9d:ad:d3:ab:a3.
4
Are you sure you want to continue connecting (yes/no)? yes
5
Warning: Permanently added '10.0.0.3' (RSA) to the list of known hosts.
6
7
$ while true; do echo -e 'HTTP/1.0 200 OK \r\n\r\nServer1' | sudo nc -l -p 80 ; done
8
$ while true; do echo -e 'HTTP/1.0 200 OK \r\n\r\nServer2' | sudo nc -l -p 80 ; done
Copied!
If we check with curl the VIP's floating IP, we'll see that in every connection one of both servers reply with his name.
1
[[email protected] ~]$ curl http://172.24.4.3
2
Server1
3
[[email protected] ~]$ curl http://172.24.4.3
4
Server2
5
[[email protected] ~]$ curl http://172.24.4.3
6
Server1
7
[[email protected] ~]$ curl http://172.24.4.3
8
Server2
Copied!
Last modified 1yr ago
Copy link