-
Notifications
You must be signed in to change notification settings - Fork 7
/
haproxy.yaml
324 lines (301 loc) · 10 KB
/
haproxy.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
heat_template_version: 2015-10-15
description: >
This HEAT template creates a pair of servers running keepalived in a
master / slave configuration controlling a virtual-ip address. It
defines a neutron port for the VIP so that a floating IP address can
be associated, and then HAProxy is run on both servers to create an
HA Load-Balancer service.
Optionally deploys Consul and Consul-template for service discovery
and dynamic load-balancer configuration.
parameters:
key_name:
type: string
description: SSH Key Pair
constraints:
- custom_constraint: nova.keypair
flavor:
type: string
description: Flavor to use for the haproxy server
default: t1.small
constraints:
- custom_constraint: nova.flavor
image:
type: string
description: Image ID or image name to use for the haproxy server
default: "CentOS 7"
constraints:
- custom_constraint: glance.image
router:
type: string
description: Name of the router used to connect to the external network
default: InternetGW
external_network:
type: string
description: Name of the external network used for floating ip addresses
default: internet
vrrp_subnet_cidr:
type: string
description: VRRP Subnet CIDR address
default: 172.16.1.0/24
vrrp_subnet_dns:
type: string
description: DNS Servers to configure on the vrrp subnet
default: 8.8.8.8
dmz_subnet_cidr:
type: string
description: DMZ Subnet CIDR address
default: 10.0.0.0/24
haproxy_ports:
type: comma_delimited_list
label: ports
default: "80,443"
deploy_consul:
type: boolean
description: Optionally deploy consul for service discovery
default: false
keepalived_password:
type: string
description: Password for keepalived encryption
default: SUperS3creT
resources:
vrrp_net:
type: OS::Neutron::Net
properties:
admin_state_up: true
name: vrrp_net
vrrp_subnet:
type: OS::Neutron::Subnet
properties:
name: vrrp_subnet
network: { get_resource: vrrp_net }
allocation_pools:
- start:
list_join: ['.', [ str_split: ['.', { get_param: vrrp_subnet_cidr }, 0], str_split: ['.', { get_param: vrrp_subnet_cidr }, 1], str_split: ['.', { get_param: vrrp_subnet_cidr }, 2], '20' ]]
end:
list_join: ['.', [ str_split: ['.', { get_param: vrrp_subnet_cidr }, 0], str_split: ['.', { get_param: vrrp_subnet_cidr }, 1], str_split: ['.', { get_param: vrrp_subnet_cidr }, 2], '200' ]]
cidr: { get_param: vrrp_subnet_cidr }
dns_nameservers: [ { get_param: vrrp_subnet_dns } ]
gateway_ip:
list_join: ['.', [ str_split: ['.', { get_param: vrrp_subnet_cidr }, 0], str_split: ['.', { get_param: vrrp_subnet_cidr }, 1], str_split: ['.', { get_param: vrrp_subnet_cidr }, 2], '1' ]]
ip_version: 4
vrrp_gw:
type: OS::Neutron::RouterInterface
properties:
router: { get_param: router }
subnet: { get_resource: vrrp_subnet }
haproxy_secgroup:
type: OS::Neutron::SecurityGroup
properties:
rules:
- direction: ingress
protocol: 112
remote_group_id:
remote_mode: remote_group_id
- direction: ingress
protocol: icmp
remote_ip_prefix: 0.0.0.0/0
- direction: ingress
protocol: tcp
remote_ip_prefix: 0.0.0.0/0
port_range_min: 80
port_range_max: 80
ssh_int_secgroup:
type: OS::Neutron::SecurityGroup
properties:
rules:
- protocol: tcp
remote_ip_prefix: { get_param: vrrp_subnet_cidr }
port_range_min: 22
port_range_max: 22
- protocol: tcp
remote_ip_prefix: { get_param: dmz_subnet_cidr }
port_range_min: 22
port_range_max: 22
# consul_secgroup:
# type: OS::Neutron::SecurityGroup
# properties:
# rules:
# - direction: ingress
# protocol: tcp
# remote_group_id:
# remote_mode: remote_group_id
# port_range_min: 8300
# port_range_max: 8302
# - direction: ingress
# protocol: udp
# remote_group_id:
# remote_mode: remote_group_id
# port_range_min: 8301
# port_range_max: 8302
# - direction: ingress
# protocol: tcp
# remote_group_id:
# remote_mode: remote_group_id
# port_range_min: 8400
# port_range_max: 8400
# - direction: ingress
# protocol: tcp
# remote_group_id:
# remote_mode: remote_group_id
# port_range_min: 8500
# port_range_max: 8500
# - direction: ingress
# protocol: tcp
# remote_group_id:
# remote_mode: remote_group_id
# port_range_min: 8600
# port_range_max: 8600
# - direction: ingress
# protocol: udp
# remote_group_id:
# remote_mode: remote_group_id
# port_range_min: 8600
# port_range_max: 8600
haproxy_vip_port:
type: OS::Neutron::Port
properties:
network: { get_resource: vrrp_net }
fixed_ips:
- ip_address:
list_join: ['.', [ str_split: ['.', { get_param: vrrp_subnet_cidr }, 0], str_split: ['.', { get_param: vrrp_subnet_cidr }, 1], str_split: ['.', { get_param: vrrp_subnet_cidr }, 2], '201' ]]
security_groups:
- { get_resource: haproxy_secgroup }
haproxy_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network: { get_param: external_network }
port_id: { get_resource: haproxy_vip_port }
depends_on: vrrp_gw
haproxy_1_port:
type: OS::Neutron::Port
properties:
network: { get_resource: vrrp_net }
allowed_address_pairs:
- ip_address:
list_join: ['.', [ str_split: ['.', { get_param: vrrp_subnet_cidr }, 0], str_split: ['.', { get_param: vrrp_subnet_cidr }, 1], str_split: ['.', { get_param: vrrp_subnet_cidr }, 2], '201' ]]
fixed_ips:
- subnet_id: { get_resource: vrrp_subnet }
security_groups:
- { get_resource: haproxy_secgroup }
- { get_resource: ssh_int_secgroup }
# - { get_resource: consul_secgroup }
haproxy_2_port:
type: OS::Neutron::Port
properties:
network: { get_resource: vrrp_net }
allowed_address_pairs:
- ip_address:
list_join: ['.', [ str_split: ['.', { get_param: vrrp_subnet_cidr }, 0], str_split: ['.', { get_param: vrrp_subnet_cidr }, 1], str_split: ['.', { get_param: vrrp_subnet_cidr }, 2], '201' ]]
fixed_ips:
- subnet_id: { get_resource: vrrp_subnet }
security_groups:
- { get_resource: haproxy_secgroup }
- { get_resource: ssh_int_secgroup }
# - { get_resource: consul_secgroup }
haproxy_cluster:
type: OS::Nova::ServerGroup
properties:
name: Haproxy Cluster
policies: ['anti-affinity']
haproxy_1_server:
type: OS::Nova::Server
properties:
name: haproxy01
flavor: { get_param: flavor }
image: { get_param: image }
key_name: { get_param: key_name }
scheduler_hints: { group: { get_resource: haproxy_cluster }}
networks:
- port: { get_resource: haproxy_1_port }
user_data_format: SOFTWARE_CONFIG
user_data: { get_attr: [config_agent, config] }
haproxy_2_server:
type: OS::Nova::Server
properties:
name: haproxy02
flavor: { get_param: flavor }
image: { get_param: image }
key_name: { get_param: key_name }
scheduler_hints: { group: { get_resource: haproxy_cluster }}
networks:
- port: { get_resource: haproxy_2_port }
user_data_format: SOFTWARE_CONFIG
user_data: { get_attr: [config_agent, config] }
# Install, configure and enable the Heat configuration agent
config_agent:
type: collect-config-setup/install_config_agent_centos_yum.yaml
keepalived_config:
type: OS::Heat::SoftwareConfig
properties:
group: script
inputs:
- name: state
- name: priority
- name: password
outputs:
- name: result
config:
str_replace:
template: { get_file: 'files/keepalived.conf' }
params:
$vip: { get_attr: [haproxy_vip_port, fixed_ips, 0, ip_address] }
keepalived_master_config:
type: OS::Heat::SoftwareDeployment
properties:
signal_transport: CFN_SIGNAL
config:
get_resource: keepalived_config
server:
get_resource: haproxy_1_server
input_values:
state: MASTER
priority: 100
password: { get_param: keepalived_password }
keepalived_slave_config:
type: OS::Heat::SoftwareDeployment
properties:
signal_transport: CFN_SIGNAL
config:
get_resource: keepalived_config
server:
get_resource: haproxy_2_server
input_values:
state: BACKUP
priority: 50
password: { get_param: keepalived_password }
install_software:
type: OS::Heat::SoftwareConfig
properties:
group: script
inputs:
- name: deploy_consul
config: { get_file: 'files/install_software.sh' }
deploy_software:
type: OS::Heat::SoftwareDeploymentGroup
depends_on: [ keepalived_master_config, keepalived_slave_config ]
properties:
config:
get_resource: install_software
servers:
haproxy01: { get_resource: haproxy_1_server }
haproxy02: { get_resource: haproxy_2_server }
input_values:
deploy_consul: { get_param: deploy_consul }
haproxy_config:
type: OS::Heat::SoftwareConfig
properties:
group: script
config:
str_replace:
template: { get_file: 'files/haproxy.cfg' }
params:
$vip: { get_attr: [haproxy_vip_port, fixed_ips, 0, ip_address] }
deploy_haproxy_config:
type: OS::Heat::SoftwareDeploymentGroup
depends_on: [ deploy_software ]
properties:
config:
get_resource: haproxy_config
servers:
haproxy01: { get_resource: haproxy_1_server }
haproxy02: { get_resource: haproxy_2_server }