Chapter 4. Using the Orchestration service (heat) for autoscaling After you deploy the services required to provide autoscaling, you must configure the environment so that the Orchestration service (heat) can manage instances for autoscaling. Prerequisites A deployed Red Hat OpenStack Services on OpenShift (RHOSO) environment. Ceilometer, Autoscaling, MetricStorage, and the Orchestration service are enabled on the control plane. 4.1. Configuring a heat template for autoscaling Procedure You can configure an Orchestration service (heat) template to create the instances, and configure alarms that create and scale instances when triggered. This procedure uses example values that might differ from your environment. Prerequisites You have deployed the cloud with the autoscaling services. Procedure Access the openstackclient pod: Create a directory for your templates, for example /tmp/templates/ : Create an instance configuration template, for example /tmp/templates/instance.yaml : Add the following configuration to your instance.yaml file: Create the resource to reference in the heat template: Create the deployment template for the Orchestration service to control instance scaling: 4.2. Creating the stack deployment for autoscaling Create the stack deployment for autoscaling. This procedure uses example values that might differ from your environment. Prerequisites You have configured a heat template for automatically scaling instances. Procedure Access the openstack client pod: Create the stack: Verification Verify that you created the stack successfully: Verify that you created the stack resources, including alarms, scaling policies, and the autoscaling group: Verify that an instance was launched by the stack creation: Verify that you created the alarms for the stack: List the alarm IDs. If the state of the alarm is insufficient data , try checking again after the data collects: List the resources for the stack and note the physical_resource_id values for the cpu_alarm_high and cpu_alarm_low resources: Verify that metric resources and measurements exist for the stack. Use the ID of the stack for the server_group:

Commands:
oc rsh openstackclient
mkdir -p /tmp/templates
cat <<EOF > /tmp/templates/instance.yaml heat_template_version: wallaby description: Template to control scaling of VNF instance parameters: metadata: type: json image: type: string description: image used to create instance default: cirros flavor: type: string description: instance flavor to be used default: m1.small network: type: string description: project network to attach instance to default: private external_network: type: string description: network used for floating IPs default: public resources: vnf: type: OS::Nova::Server properties: flavor: {get_param: flavor} image: { get_param: image } metadata: { get_param: metadata } networks: - port: { get_resource: port } port: type: OS::Neutron::Port properties: network: {get_param: network} security_groups: - basic floating_ip: type: OS::Neutron::FloatingIP properties: floating_network: {get_param: external_network } floating_ip_assoc: type: OS::Neutron::FloatingIPAssociation properties: floatingip_id: { get_resource: floating_ip } port_id: { get_resource: port } EOF
cat <<EOF > /tmp/templates/resources.yaml resource_registry: "OS::Nova::Server::VNF": /tmp/templates/instance.yaml EOF
cat <<EOF > /tmp/templates/autoscaling.yaml heat_template_version: wallaby description: Example auto scale group, policy and alarm resources: autoscalinggroup: type: OS::Heat::AutoScalingGroup properties: cooldown: 300 desired_capacity: 1 max_size: 3 min_size: 1 resource: # Configure the resource to be autoscaled type: OS::Nova::Server::VNF properties: metadata: {"metering.server_group": {get_param: "OS::stack_id"}} scaleup_policy: type: OS::Heat::ScalingPolicy properties: adjustment_type: change_in_capacity auto_scaling_group_id: { get_resource: autoscalinggroup } cooldown: 300 scaling_adjustment: 1 scaledown_policy: type: OS::Heat::ScalingPolicy properties: adjustment_type: change_in_capacity auto_scaling_group_id: { get_resource: autoscalinggroup } cooldown: 300 scaling_adjustment: -1 cpu_alarm_high: type: OS::Aodh::PrometheusAlarm properties: description: Scale up if CPU > 80% threshold: 80 # 80% comparison_operator: gt alarm_actions: - str_replace: template: trust+url params: url: {get_attr: [scaleup_policy, signal_url]} query: str_replace: # ceilometer_cpu metric is in ns. Divide the rate by 10000000 to get percentage # The time duration in [] should be higher than ceilometer polling interval # You can add {ceilometer polling} to {prometheus scrape interval} to calculate the value. # The default value is 150s. template: "(rate(ceilometer_cpu{server_group=~'stack_id'}[150s]))/10000000" params: stack_id: {get_param: OS::stack_id} cpu_alarm_low: type: OS::Aodh::PrometheusAlarm properties: description: Scale up if CPU < 20% threshold: 20 # 20% comparison_operator: lt alarm_actions: - str_replace: template: trust+url params: url: {get_attr: [scaledown_policy, signal_url]} query: str_replace: # ceilometer_cpu metric is in ns. Divide the rate by 10000000 to get percentage # The time duration in [] should be higher than ceilometer polling interval # You can add {ceilometer polling} to {prometheus scrape interval} to calculate the value. # The default value is 150s. template: "(rate(ceilometer_cpu{server_group=~'stack_id'}[150s]))/10000000" params: stack_id: {get_param: OS::stack_id} outputs: scaleup_policy_signal_url: value: {get_attr: [scaleup_policy, signal_url]} scaledown_policy_signal_url: value: {get_attr: [scaledown_policy, signal_url]} EOF
oc rsh openstackclient
openstack stack create -t /tmp/templates/autoscaling.yaml -e /tmp/templates/resources.yaml stack1
openstack stack show stack1 -c id -c stack_status +--------------+--------------------------------------+ | Field | Value | +--------------+--------------------------------------+ | id | 9ac44c45-4917-4cd5-a713-9ef7828d8457 | | stack_status | CREATE_COMPLETE | +--------------+--------------------------------------+
export STACK_ID=USD(openstack stack show stack1 -c id -f value) openstack stack resource list USDSTACK_ID +------------------+--------------------------------------+----------------------------+-----------------+----------------------+ | resource_name | physical_resource_id | resource_type | resource_status | updated_time | +------------------+--------------------------------------+----------------------------+-----------------+----------------------+ | scaleup_policy | 3cfb2a746dcf4fb6b3284b6c164e4ff5 | OS::Heat::ScalingPolicy | CREATE_COMPLETE | 2024-03-26T09:17:54Z | | scaledown_policy | ef60360ae7564abda088e67b3cc542f4 | OS::Heat::ScalingPolicy | CREATE_COMPLETE | 2024-03-26T09:17:54Z | | cpu_alarm_low | 95503054-aada-457c-b586-f98a88b00962 | OS::Aodh::PrometheusAlarm | CREATE_COMPLETE | 2024-03-26T09:17:54Z | | cpu_alarm_high | 65be604f-1262-4567-851d-ac28ae1bb178 | OS::Aodh::PrometheusAlarm | CREATE_COMPLETE | 2024-03-26T09:17:54Z | | autoscalinggroup | 8c4fea31-3beb-47b7-841d-fe82fb284628 | OS::Heat::AutoScalingGroup | CREATE_COMPLETE | 2024-03-26T09:17:54Z | +------------------+--------------------------------------+----------------------------+-----------------+----------------------+
openstack server list --long | grep USDSTACK_ID | 9e2e9266-d69e-4de1-8b3a-e75f7111d1d9 | autoscaling_server_stack1-autoscalinggroup-oqmxiukze6dg-hdtuapbjxcow-q366nn4k5utr | ACTIVE | None | Running | private=192.168.0.209, 192.168.122.205 | cirros | 239959f7-3d16-4744-8eca-435cdfc1a4cf | m1.small | nova | edpm-compute-0.ctlplane.example.com | metering.server_group='9ac44c45-4917-4cd5-a713-9ef7828d8457' | UP |
openstack alarm list +--------------------------------------+------------+------------------------------------+-------+----------+---------+ | alarm_id | type | name | state | severity | enabled | +--------------------------------------+------------+------------------------------------+-------+----------+---------+ | 65be604f-1262-4567-851d-ac28ae1bb178 | prometheus | stack1-cpu_alarm_high-q5yw2fg4h2vh | ok | low | True | | 95503054-aada-457c-b586-f98a88b00962 | prometheus | stack1-cpu_alarm_low-hjmpszetdpsw | alarm | low | True | +--------------------------------------+------------+------------------------------------+-------+----------+---------+
openstack stack resource list USDSTACK_ID +------------------+--------------------------------------+----------------------------+-----------------+----------------------+ | resource_name | physical_resource_id | resource_type | resource_status | updated_time | +------------------+--------------------------------------+----------------------------+-----------------+----------------------+ | scaleup_policy | 3cfb2a746dcf4fb6b3284b6c164e4ff5 | OS::Heat::ScalingPolicy | CREATE_COMPLETE | 2024-03-26T09:17:54Z | | scaledown_policy | ef60360ae7564abda088e67b3cc542f4 | OS::Heat::ScalingPolicy | CREATE_COMPLETE | 2024-03-26T09:17:54Z | | cpu_alarm_low | 95503054-aada-457c-b586-f98a88b00962 | OS::Aodh::PrometheusAlarm | CREATE_COMPLETE | 2024-03-26T09:17:54Z | | cpu_alarm_high | 65be604f-1262-4567-851d-ac28ae1bb178 | OS::Aodh::PrometheusAlarm | CREATE_COMPLETE | 2024-03-26T09:17:54Z | | autoscalinggroup | 8c4fea31-3beb-47b7-841d-fe82fb284628 | OS::Heat::AutoScalingGroup | CREATE_COMPLETE | 2024-03-26T09:17:54Z | +------------------+--------------------------------------+----------------------------+-----------------+----------------------+
openstack metric query "(rate(ceilometer_cpu{server_group=~'ac2e87ba-f55e-46e7-8f8d-f09fe91d63d1'}[150s]))/10000000" +---------+--------------------------------------+----------------------------------------+----------------------------------+--------------------------------------+-------------------------------------------------------------------------+--------------------------------------+------+------+----------------------------------+----------------------------------------------------------+--------------------+ | counter | cpu | instance | project | resource | resource_name | server_group | type | unit | user | vm_instance | value | +---------+--------------------------------------+----------------------------------------+----------------------------------+--------------------------------------+-------------------------------------------------------------------------+--------------------------------------+------+------+----------------------------