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-ycpt-42udzur6y242-nrgl6iphh46i-server-ewgo3dhkgblm
+--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+
| ID | Name | MAC Address | Fixed IP Addresses | Status |
+--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+
| 570260e2-4659-447b-957b-2483817394dd | | fa:16:3e:c7:92:22 | ip_address='10.10.3.179', 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
sudo apt install stress
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 |
+--------------------------------------+--------------------------------------------+---------------------------------------------+-------+----------+---------+
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-ycpt-sn72lqvcjhq7-eqhn3s4jsorb-server-vzye4rbbwsah | BUILD | my-wordpress-network-2=10.10.3.180 | | a1-ram2-disk20-perf1 |
| 1b7c799b-ae64-49aa-bba5-eb2eeb5acc81 | Wo-ycpt-42udzur6y242-nrgl6iphh46i-server-ewgo3dhkgblm | ACTIVE | my-wordpress-network-2=10.10.3.179 | | a1-ram2-disk20-perf1 |
| 486406b5-2289-4caf-95ba-92d46db721e0 | Wordpress-stockage-vkzedswkl6i6 | ACTIVE | my-wordpress-network-2=10.10.3.20 | | a1-ram2-disk80-perf1 |
| 522c6319-7dd9-43ab-a9d4-5d56f5378092 | Wordpress-db_1-lyay6o3v2pl3 | ACTIVE | my-wordpress-network-2=10.10.3.10 | | a2-ram4-disk20-perf1 |
| aa3bdb2c-163d-40fa-afe7-da138059427a | Wordpress-db_2-nttqvyxhl4m5 | ACTIVE | my-wordpress-network-2=10.10.3.11 | | a2-ram4-disk20-perf1 |
+--------------------------------------+-------------------------------------------------------+--------+------------------------------------+-------+----------------------+
The autoscale works as expected, a new VM is being provisionned and will automatically receive requests fron the loadbalancer.