-
Notifications
You must be signed in to change notification settings - Fork 12
/
auto_scaling.yaml
139 lines (123 loc) · 4.01 KB
/
auto_scaling.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
heat_template_version: 2021-04-16
description: Example auto scale group policy and alarm
parameters:
key_name:
type: string
description: Keypair for SSH access
constraints:
- custom_constraint: nova.keypair
description: Must be an existing keypair
flavor:
type: string
description: Flavor
default: t3.xsmall
constraints:
- custom_constraint: nova.flavor
description: Must be an existing flavor
image:
type: string
description: Image ID or name
default: NeCTAR Ubuntu 22.04 LTS (Jammy) amd64
availability_zone:
type: string
description: Availability Zone
resources:
security_group:
# https://docs.openstack.org/heat/latest/template_guide/openstack.html#OS::Neutron::SecurityGroup
type: OS::Neutron::SecurityGroup
properties:
rules:
- remote_ip_prefix: 0.0.0.0/0
protocol: icmp
- remote_ip_prefix: 0.0.0.0/0
protocol: tcp
port_range_min: 22
port_range_max: 22
- remote_ip_prefix: 0.0.0.0/0
protocol: tcp
port_range_min: 80
port_range_max: 80
scaling_group:
# https://docs.openstack.org/heat/pike/template_guide/openstack.html#OS::Heat::AutoScalingGroup
type: OS::Heat::AutoScalingGroup
properties:
cooldown: 300
desired_capacity: 1
max_size: 3
min_size: 1
resource:
type: OS::Nova::Server
properties:
key_name: { get_param: key_name }
image: { get_param: image }
flavor: { get_param: flavor }
availability_zone: { get_param: availability_zone }
security_groups:
- { get_resource: security_group }
networks:
- allocate_network: auto
metadata:
metering.server_group: { get_param: "OS::stack_id" }
scaleup_policy:
# https://docs.openstack.org/heat/pike/template_guide/openstack.html#OS::Heat::ScalingPolicy
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: { get_resource: scaling_group }
cooldown: 300
scaling_adjustment: 1
scaledown_policy:
# https://docs.openstack.org/heat/pike/template_guide/openstack.html#OS::Heat::ScalingPolicy
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: { get_resource: scaling_group }
cooldown: 300
scaling_adjustment: -1
cpu_alarm_high:
# https://docs.openstack.org/heat/pike/template_guide/openstack.html#OS::Aodh::GnocchiAggregationByResourcesAlarm
type: OS::Aodh::GnocchiAggregationByResourcesAlarm
properties:
description: Scale up if CPU > 75%
metric: cpu_util
aggregation_method: mean
granularity: 600
evaluation_periods: 1
threshold: 75
resource_type: instance
comparison_operator: gt
alarm_actions:
- str_replace:
template: trust+url
params:
url: { get_attr: [scaleup_policy, signal_url] }
query:
list_join:
- ''
- - { '=': { server_group: { get_param: "OS::stack_id" } } }
cpu_alarm_low:
# https://docs.openstack.org/heat/pike/template_guide/openstack.html#OS::Aodh::GnocchiAggregationByResourcesAlarm
type: OS::Aodh::GnocchiAggregationByResourcesAlarm
properties:
description: Scale down if CPU < 15%
metric: cpu_util
aggregation_method: mean
granularity: 600
evaluation_periods: 1
threshold: 15
resource_type: instance
comparison_operator: lt
alarm_actions:
- str_replace:
template: trust+url
params:
url: {get_attr: [scaledown_policy, signal_url]}
query:
list_join:
- ''
- - { '=': { server_group: { 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] }