Skip to content

WordPress : High Available and auto scalable

Create a Highly Available and auto-scalable WordPress blog in a single command.

$ openstack stack create -t wordpress.yaml wordpress

WordPress

Architecture

WordPress

There are three kinds of nodes:

  • Database node : In this setup there's only one node hosting the database.

  • Web nodes : The web nodes run Apache and serve HTTP requests. They connect to the database node. The number of web nodes depends on the CPU usage and may vary from 1 to 3 nodes.

The nodes increase or decrease when CPU usage is above 60% or below 30%.

  • Load Balancer nodes : These nodes run haproxy and redirect the traffic to the web node(s). They are highly available, act as Active/Passive and manage the public IP.

Prerequisites

Heat templates

Resources files are available on Infomaniak Github

Get started with cloning the repository, you should get two Heat templates wordpress.yaml and lb_server.yaml.

Create the stack

$ openstack stack create -t wordpress.yaml wordpress

The stack takes several minutes to be created and operational.

Once created check the URL and the public IP to finish the wordpress setup :

In the example below it is: http://195.15.244.24

$ openstack stack show wordpress --fit-width
+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field                 | Value                                                                                                                                                                            |
+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                    | 6ac35326-b5a9-4124-aace-39430ab0c06c                                                                                                                                             |
| stack_name            | wordpress                                                                                                                                                                        |
| description           | AutoScaling Wordpress                                                                                                                                                            |
| creation_time         | 2021-05-03T13:25:25Z                                                                                                                                                             |
| updated_time          | None                                                                                                                                                                             |
| stack_status          | CREATE_COMPLETE                                                                                                                                                                  |
| stack_status_reason   | Stack CREATE completed successfully                                                                                                                                              |
| parameters            | OS::project_id: d1440aa24a65411fb9bac2b842c8defa                                                                                                                                 |
|                       | OS::stack_id: 6ac35326-b5a9-4124-aace-39430ab0c06c                                                                                                                               |
|                       | OS::stack_name: wordpress                                                                                                                                                        |
|                       | database_flavor: a2-ram4-disk20-perf1                                                                                                                                            |
|                       | database_name: wordpress                                                                                                                                                         |
|                       | database_user: wordpress                                                                                                                                                         |
|                       | flavor: a2-ram4-disk20-perf1                                                                                                                                                     |
|                       | floating_network_id: ext-floating1                                                                                                                                               |
|                       | image: Debian 10.11 buster                                                                                                                                                       |
|                       | key: yubikey-taylor                                                                                                                                                              |
|                       | network: my-wordpress-network                                                                                                                                                    |
|                       | subnet_id: my-wordpress-subnet                                                                                                                                                   |
|                       |                                                                                                                                                                                  |
| outputs               | - description: This public URL and IP that can be used to access the Wordpress site.                                                                                             |
|                       |   output_key: website_url                                                                                                                                                        |
|                       |   output_value: http://195.15.244.24                                                                                                                                             |
|                       |                                                                                                                                                                                  |
| links                 | - href: https://api.pub1.infomaniak.cloud/v1/d1440aa24a65411fb9bac2b842c8defa/stacks/wordpress/6ac35326-b5a9-4124-aace-39430ab0c06c                                              |
|                       |   rel: self                                                                                                                                                                      |
|                       |                                                                                                                                                                                  |
| deletion_time         | None                                                                                                                                                                             |
| notification_topics   | []                                                                                                                                                                               |
| capabilities          | []                                                                                                                                                                               |
| disable_rollback      | True                                                                                                                                                                             |
| timeout_mins          | None                                                                                                                                                                             |
| stack_owner           | taylor                                                                                                                                                                           |
| parent                | None                                                                                                                                                                             |
| stack_user_project_id | 4b936b75dd934fd8bb0644709b531a59                                                                                                                                                 |
| tags                  | []                                                                                                                                                                               |
|                       |                                                                                                                                                                                  |
+-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Servers and IP

You can list freshly created servers to check their status, flavor and other informations.

Info

​ Database and web nodes are classic virtual machines

$ openstack server list
+--------------------------------------+-------------------------------------------------------+--------+------------------------------------------------+-------------------------------+----------------------+
| ID                                   | Name                                                  | Status | Networks                                       | Image                         | Flavor               |
+--------------------------------------+-------------------------------------------------------+--------+------------------------------------------------+-------------------------------+----------------------+
| b5cbd7f6-cf22-4d2b-9968-47e7e92003d9 | wo-pbso-lwlc5mvjfq27-pl3fnem36r5k-server-tmddooqgsz5q | ACTIVE | my-wordpress-network=10.11.12.211              | Debian 10.11 buster           | a2-ram4-disk20-perf1 |
| 8a82e7ad-0c42-4cd1-a7f0-4ea7a6755f20 | wordpress-db-s7inj4sfzgq2                             | ACTIVE | my-wordpress-network=10.11.12.140              | Debian 10.11 buster           | a2-ram4-disk20-perf1 |
+--------------------------------------+-------------------------------------------------------+--------+------------------------------------------------+-------------------------------+----------------------+

Where are the loadbalancers ? 🤔

Well, loadbalancer nodes use the Octavia project, even though their are actual virtual machine running HAProxy you have to issue openstack loadbalancer command family to interact with them.

More details here.

$ openstack loadbalancer list
+--------------------------------------+---------------------------+----------------------------------+-------------+---------------------+------------------+----------+
| id                                   | name                      | project_id                       | vip_address | provisioning_status | operating_status | provider |
+--------------------------------------+---------------------------+----------------------------------+-------------+---------------------+------------------+----------+
| 7acc9d54-6b33-4148-a2ef-cc3c0097e1b5 | wordpress-lb-6z4twath627y | d1440aa24a65411fb9bac2b842c8defa | 10.11.12.26 | ACTIVE              | ONLINE           | amphora  |
+--------------------------------------+---------------------------+----------------------------------+-------------+---------------------+------------------+----------+

Finally, the public IP.

The public IP is a floating IP attached to the port of the loadbalancer.

$ openstack floating ip list
+--------------------------------------+---------------------+------------------+--------------------------------------+--------------------------------------+----------------------------------+
| ID                                   | Floating IP Address | Fixed IP Address | Port                                 | Floating Network                     | Project                          |
+--------------------------------------+---------------------+------------------+--------------------------------------+--------------------------------------+----------------------------------+
| 27a2b35f-f334-4c22-a180-b7efd4ce701f | 195.15.244.24       | 10.11.12.26      | abbe8df1-e72d-4d48-bef8-a223a6fe945e | 0f9c3806-bd21-490f-918d-4a6d1c648489 | d1440aa24a65411fb9bac2b842c8defa |
+--------------------------------------+---------------------+------------------+--------------------------------------+--------------------------------------+----------------------------------+

Auto scale up and down

The auto scale uses Gnocchi project for reading metrics and Aodh project to trigger actions based on these metrics. More details about metrics here and here regarding the alerting CPU usage based.

To see the alarm status:

$ openstack alarm list
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+
| alarm_id                             | type                                       | name                                        | state | severity | enabled |
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+
| f29c6b48-501f-4b44-b608-c0d8991cd617 | gnocchi_aggregation_by_resources_threshold | wordpress-cpu_alarm_low-lqffbb77z67s        | alarm | low      | True    |
| 8c8beea0-fb77-46b1-8574-46009dad6b14 | gnocchi_aggregation_by_resources_threshold | wordpress-cpu_alarm_high-nfitaw5w2kkj       | ok    | low      | True    |
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+

wordpress-cpu_alarm_low-lqffbb77z67s state alarm means take action which is keep the number of VMs low with a minimum of 1. wordpress-cpu_alarm_high-nfitaw5w2kkj state ok means does nothing.

Testing the autoscale

Assign temporay a public IP to access the web node and to stress the cpu, after a few minutes additional web nodes should be created.

  • Reserve a floating IP
$ openstack floating ip create ext-floating1
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| created_at          | 2021-05-03T14:07:16Z                 |
| description         |                                      |
| dns_domain          | None                                 |
| dns_name            | None                                 |
| fixed_ip_address    | None                                 |
| floating_ip_address | 195.15.244.171                       |
| floating_network_id | 0f9c3806-bd21-490f-918d-4a6d1c648489 |
| id                  | 847b323f-9386-4f8b-99a1-79b1ff71e61f |
| name                | 195.15.244.171                       |
| port_details        | None                                 |
| port_id             | None                                 |
| project_id          | d1440aa24a65411fb9bac2b842c8defa     |
| qos_policy_id       | None                                 |
| revision_number     | 0                                    |
| router_id           | None                                 |
| status              | DOWN                                 |
| subnet_id           | None                                 |
| tags                | []                                   |
| updated_at          | 2021-05-03T14:07:16Z                 |
+---------------------+--------------------------------------+
  • Attach the floating IP to the web node port
$ openstack port list --server wo-pbso-lwlc5mvjfq27-pl3fnem36r5k-server-tmddooqgsz5q
+--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+
| ID                                   | Name | MAC Address       | Fixed IP Addresses                                                          | Status |
+--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+
| 570260e2-4659-447b-957b-2483817394dd |      | fa:16:3e:c7:92:22 | ip_address='10.11.12.211', subnet_id='31fdc6c2-cb37-4ca1-b7df-32ab7a60eb42' | ACTIVE |
+--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+
$ openstack floating ip set --port 570260e2-4659-447b-957b-2483817394dd 195.15.244.171
  • ssh the web node and stress the cpu
$ ssh debian@195.15.244.171
debian@wo-pbso-lwlc5mvjfq27-pl3fnem36r5k-server-tmddooqgsz5q:~$ sudo apt install stress
debian@wo-pbso-lwlc5mvjfq27-pl3fnem36r5k-server-tmddooqgsz5q:~$ stress -c 2
  • Check the alarms and the number of VMs

CPU metrics are aggregated every 5 minutes so it can take up to 5 minutes to start new VMs.

$ openstack alarm list
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+
| alarm_id                             | type                                       | name                                        | state | severity | enabled |
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+
| f29c6b48-501f-4b44-b608-c0d8991cd617 | gnocchi_aggregation_by_resources_threshold | wordpress-cpu_alarm_low-lqffbb77z67s        | ok    | low      | True    |
| 8c8beea0-fb77-46b1-8574-46009dad6b14 | gnocchi_aggregation_by_resources_threshold | wordpress-cpu_alarm_high-nfitaw5w2kkj       | ok    | low      | True    |
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+
OK for both alarms means that the CPU usage is between the thresholds:

wordpress-cpu_alarm_low-lqffbb77z67s < cpu_usage < wordpress-cpu_alarm_high-nfitaw5w2kkj

  • Check the alarms and the number of VMs after a few minutes
$ openstack alarm list
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+
| alarm_id                             | type                                       | name                                        | state | severity | enabled |
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+
| f29c6b48-501f-4b44-b608-c0d8991cd617 | gnocchi_aggregation_by_resources_threshold | wordpress-cpu_alarm_low-lqffbb77z67s        | ok    | low      | True    |
| 8c8beea0-fb77-46b1-8574-46009dad6b14 | gnocchi_aggregation_by_resources_threshold | wordpress-cpu_alarm_high-nfitaw5w2kkj       | alarm | low      | True    |
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+

wordpress-cpu_alarm_low-lqffbb77z67s < wordpress-cpu_alarm_high-nfitaw5w2kkj < cpu_usage

New VMs shoud be created:

$ openstack server list
+--------------------------------------+-------------------------------------------------------+--------+------------------------------------------------+--------------------------------+----------------------+
| ID                                   | Name                                                  | Status | Networks                                       | Image                          | Flavor               |
+--------------------------------------+-------------------------------------------------------+--------+------------------------------------------------+--------------------------------+----------------------+
| a3cb4b3f-43b9-413c-b391-59ee82bb4367 | wo-pbso-sn72lqvcjhq7-eqhn3s4jsorb-server-vzye4rbbwsah | BUILD  |                                                | Debian 10.11 buster            | a2-ram4-disk20-perf1 |
| b5cbd7f6-cf22-4d2b-9968-47e7e92003d9 | wo-pbso-lwlc5mvjfq27-pl3fnem36r5k-server-tmddooqgsz5q | ACTIVE | my-wordpress-network=10.11.12.211              | Debian 10.11 buster            | a2-ram4-disk20-perf1 |
| 8a82e7ad-0c42-4cd1-a7f0-4ea7a6755f20 | wordpress-db-s7inj4sfzgq2                             | ACTIVE | my-wordpress-network=10.11.12.140              | Debian 10.11 buster            | a2-ram4-disk20-perf1 |
+--------------------------------------+-------------------------------------------------------+--------+------------------------------------------------+--------------------------------+----------------------+

The autoscale works as expected, a new VM is being provisionned and will automatically receive requests fron the loadbalancer.

Back to top