OpenStack Heat autoscaling
I. BACKGROUND
OpenStack's heat is a component that was added after the H version, designed to create a business process that makes it easier to manage a cluster. The virtual machines within the cluster can serve as a whole and serve the customers uniformly. Heat defines functionality as a resource and uses components such as nova,neutron,ceilometer in heat, which can be viewed as resources, described by template files, template files can be YAML format, or JSON format, generally YAML format.
The concept of autoscaling first appeared in the aws,autoscaling is a Web service designed to automatically scale by starting or terminating a virtual machine based on user-defined policies, schedule run status checks.
The auto scale in OpenStack is done with heat and ceilometer modules. Ceilometer is responsible for the collection of processing performance data, once the heat template definition of the threshold, the alarm information to heat-engine, by heat-engine transfer heat template in the definition of other OpenStack resources to achieve auto scale.
Ii. Heat autoscaling Resources
The resources involved in implementing the AutoScaling feature are as follows:
1.aws::autoscaling::autoscalinggroup
A telescopic group is a collection of instances with the same scenario, defining the maximum and minimum values for the number of instances in the group, cooling time, and so on.
Note: Cooling time refers to a period of time after a telescopic activity, during which no other stretching activities can be carried out.
The syntax is as follows:
{
' Type ': ' Aws::autoscaling::autoscalinggroup ',
' Properties ': {
' availabilityzones ': [String, ...],
"cooldown": String,
"desiredcapacity": String,
"Healthcheckgraceperiod": Integer,
" Healthchecktype ": String,
" Instanceid ": String,
" Launchconfigurationname ": String,
" Loadbalancernames ": [String, ...],
" MaxSize ": String,
" metricscollection ": [Metricscollection, ...]
"MinSize": String,
"notificationconfigurations": [Notificationconfigurations, ...],
" Placementgroup ": String,
" Tags ": [Auto scaling Tag, ...,],
" Targetgrouparns ": [String, ...],
" Termin Ationpolicies ": [String, ...,],
" Vpczoneidentifier ": [String, ...]
}
}
2.aws::autoscaling::launchconfiguration
The flex configuration defines the configuration of the instance used for flex scaling. Used by Autoscalinggroup to configure instances within a group.
The syntax is as follows:
{
' Type ': ' aws::autoscaling::launchconfiguration ',
' Properties ': {
' associatepublicipaddress ': Boolean,
"blockdevicemappings": [Blockdevicemapping, ...],
"classiclinkvpcid": String,
" Classiclinkvpcsecuritygroups ": [String, ...],
" ebsoptimized ": Boolean,
" Iaminstanceprofile ": String,
" imageID ": String,
" Instanceid ": String,
" instancemonitoring ": Boolean,
" Instancetype ": String,
"Kernelid": String,
"KeyName": String,
"Placementtenancy": String,
"Ramdiskid": String
, "Securitygroups": [Securitygroup, ...],
"Spotprice": String,
"UserData": String
}
}
3.aws::autoscaling::scalingpolicy
Adds a scalable strategy for the auto scale group, defining specific extensions or contractions, and the amount of scaling.
The syntax is as follows:
{
' Type ': ' Aws::autoscaling::scalingpolicy ',
' Properties ': {
' adjustmenttype ': String,
' Autoscalinggroupname ": String,
" cooldown ": String,
" Estimatedinstancewarmup ": Integer,
" Metricaggregationtype ": String,
" Minadjustmentmagnitude ": Integer,
" Policytype ": String,
" Scalingadjustment ": Integer,
" stepadjustments ": [Stepadjustments, ...]
}
}
In addition, the heat autoscaling also need to cooperate with os::ceilometer::alarm use, by alarm monitor the operation of the instance, once the threshold is exceeded, will produce alarms.
Third, Heat autoscaling Template
The following is a simple example:
heat_template_version:2013-05-23 description:heat template for autoscaling parameters: #定义一些变量 flavor:type:string Default:m1.small image:type:string default:1a2b3c4f-1a2b-3c4f-5d6e-4130ff5203de Availability_zone:type:stri
ng Default:nova alarm_scaleout_threshold: #阈值 type:number default:80 alarm_scalein_threshold: #阈值 type:number
Default:20 resources:neutron_network:type:os::neutron::net properties:name: {get_param: "OS::stack_name"} Neutron_subnet:type:os::neutron::subnet properties:name: {get_param: "Os::stack_name"} network_id: {get_res Ource:neutron_network} CIDR: ' 192.168.111.0/24 ' gateway_ip: ' 192.168.111.1 ' Allocation_pools:-Start: ' 192 .168.111.2 ' End: ' 192.168.111.254 ' neutron_router:type:os::neutron::router properties:name: {get_param: "O S::stack_name "} add_router_interface:type:os::neutron::routerinterface properties:router_id: {get_resource:ne Utron_router} subnet_id: {get_resource:neutron_subnet} nova_server_security_group:type:os::neutron::securitygroup properties:des Cription: ' Security group for VM ' name: {get_param: ' Os::stack_name '} rules: [{direction: ' Ingress ', Remot
E_ip_prefix: ' 0.0.0.0/0 ', port_range_min:0, port_range_max:30000, Ethertype:ipv4, protocol: ' TCP '}, {direction: ' Egress ', Remote_ip_prefix: ' 0.0.0.0/0 ', port_range_min:0, port_range_max:65535, et Hertype: ' IPv4 ', protocol: ' TCP '}, {direction: ' Egress ', Remote_ip_prefix: ' 0.0.0.0/0 ', port_range_min: 0, port_range_max:65535, EtherType: ' IPv4 ', protocol: ' UDP '}, {direction: ' Ingress ', remote_ip_p
Refix: ' 0.0.0.0/0 ', Port_range_min:null, Port_range_max:null, EtherType: ' IPv4 ', Protocol: ' ICMP '}, {direction:egress, Remote_ip_prefix: ' 0.0.0.0/0 ', Port_range_min:null, Port_range_max:null, ETH Ertype: ' IPv4 ', proTocol: ' ICMP '}] Launch_config: Configuration of instances in #Scale group Type:aws::autoscaling::launchconfiguration Properties:imag EId: {get_param:image} #实例使用的image instancetype: {get_param:flavor} #实例使用的flavor securitygroups: [Get_resource: Nova_server_security_group] UserData: | #实例启动时运行的脚本 #!/bin/bash passwd root << EOD 123456 12 3456 EOD server_group: #伸缩组 type:aws::autoscaling::autoscalinggroup properties:availabilityzones: [] Cool Down: ' Launchconfigurationname ' #冷却时间: {get_resource:launch_config} #组中实例的配置 minsize: ' 1 ' #最小实例数 MaxSize: ' 4 ' Maximum number of instances Vpczoneidentifier: [get_resource:neutron_subnet] Scaleout_policy: #向上扩展的策略 Type:aws::autoscaling::scalingpo Licy Properties:AdjustmentType:ChangeInCapacity #heat supports three ways to adjust: change_in_capacity (new = current + Adjustment), #ex Act_capacity (new = Adjustment), percent_change_in_capacity (adjusted according to the percentage of adjustment in the base of current) Autoscalinggroupname : {Get_resource:server_group} scalingadjustment: ' 1 ' #每次的调整量, that is to add an instance scalein_policy: #向下收缩的策略 type:aws::autoscaling::scalingpolicy prope Rties:AdjustmentType:ChangeInCapacity autoscalinggroupname: {get_resource:server_group} scalingadjustment: '
-1 ' #每次的调整量, that is, to reduce an instance Neutron_port:type:os::neutron::P ort properties:network_id: {get_resource:neutron_network} Fixed_ips:-subnet_id: {get_resource:neutron_subnet} security_groups: [{Get_resource:nova_server_securit Y_group}] Alarm_scaleout: #定义一个 ceilometer alarm type:os::ceilometer::alarm properties:description:scale-up I f the average CPU > 80% for minute meter_name:cpu_util #监控虚拟机的 cpu_util statistic:avg #statistic calculated as Avg The mean value method period:600 #统计周期 evaluation_periods:1 #连续几个周期才算有效 repeat_actions:true threshold: {get_param:alarm_s
Caleout_threshold}# cpu_util threshold alarm_actions: action when #该告警在alarm state. -{get_attr: [Scaleout_policy, Alarmurl]} matching_metadata: {'Metadata.user_metadata.groupname ': {get_resource: ' Server_group '}} comparison_operator:gt #检测值和阈值的比较方式为 GT is greater than alarm_
Scalein:type:os::ceilometer::alarm Properties:description:scale-down If the average CPU < 20% for ten minutes Meter_name:cpu_util statistic:avg period:600 evaluation_periods:1 repeat_actions:true threshold: { Get_param:alarm_scalein_threshold} alarm_actions:-{get_attr: [Scalein_policy, Alarmurl]} matching_metadata: {' Metadata.user_metadata.groupname ': {get_resource: ' Server_group '}} comparison_operator:lt# detection value and threshold comparison method is LT that is less than OUTP Uts:scale_in_url:value: {get_attr: [Scalein_policy, Alarmurl]} scale_out_url:value: {get_attr: [Scaleout_po
Licy, Alarmurl]}
The function of this stack is to monitor the CPU usage of the instance, and when CPU usage is greater than 80%, a new instance will be started, and when CPU utilization is less than 20%, an instance will be reduced.
Thank you for reading, I hope to help you, thank you for your support for this site!