forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alb-create-ipv4-load-balancer-and-dnsrecord.yml
358 lines (358 loc) · 11.8 KB
/
alb-create-ipv4-load-balancer-and-dnsrecord.yml
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: 'Ali Cloud application-oriented load balancer ALB support HTTP, HTTPS, and QUIC protocols and are dedicated to the network application layer, providing powerful service processing capabilities. This article describes how to quickly create an instance of an IPv4 version of ALB and forward access requests from an IPv4 client to a back-end server. '
zh-cn: 阿里云应用型负载均衡ALB支持HTTP、HTTPS和QUIC协议,专门面向网络应用层,提供强大的业务处理能力。本文介绍如何快速创建一个IPv4版本的ALB实例,并将来自IPv4客户端的访问请求转发至后端服务器。
Parameters:
VSwitchZoneId1:
Type: String
Label:
en: VSwitch Availability Zone 1
zh-cn: 交换机可用区1
Description:
zh-cn: ALB支持多可用区部署,为保障业务高可用,请至少选择2个可用区,不能与交换机可用区2相同。
en: 'ALB support multiple availability zones. To ensure high service availability, select at least two availability zones, which cannot be the same as switch availability zone 2. '
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
VSwitchZoneId2:
Type: String
Label:
en: VSwitch Availability Zone 2
zh-cn: 交换机可用区2
Description:
zh-cn: ALB支持多可用区部署,为保障业务高可用,请至少选择2个可用区,不能与交换机可用区1相同。
en: 'ALB support multiple availability zones. To ensure high service availability, select at least two availability zones, which cannot be the same as switch availability zone 1. '
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
EcsInstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例类型
Description:
zh-cn: 填写交换机可用区1可用区下可使用的规格;<br>通用规格:<font color='red'><b>ecs.g6.xlarge</b></font><br>注:可用区可能不支持通用规格<br>规格详见:<a href='https://help.aliyun.com/document_detail/25378.html' target='_blank'><b><font color='blue'>实例规格族</font></a></b>
en: 'Fill in the specifications that can be used under the VSwitch availability zone 1;</b></font><br>general specifications:<font color=''red''><b>ecs.g6.xlarge</b></font><br>note: a few zones do not support general specifications<br>see detail: <a href=''https://www.alibabacloud.com/help/en/doc-detail/25378.html'' target=''_blank''><b><font color=''blue''>Instance Specification Family</font></a></b>'
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
SystemDiskCategory:
Type: String
Label:
en: System Disk Category
zh-cn: 系统盘类型
Description:
en: '<font color=''blue''><b>Optional values:</b></font><br>[cloud_efficiency: <font color=''green''>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color=''green''>SSD Cloud Disk</font>]<br>[cloud_essd: <font color=''green''>ESSD Cloud Disk</font>]<br>[cloud: <font color=''green''>Cloud Disk</font>]<br>[ephemeral_ssd: <font color=''green''>Local SSD Cloud Disk</font>]'
zh-cn: '<font color=''blue''><b>可选值:</b></font><br>[cloud_efficiency: <font color=''green''>高效云盘</font>]<br>[cloud_ssd: <font color=''green''>SSD云盘</font>]<br>[cloud_essd: <font color=''green''>ESSD云盘</font>]<br>[cloud: <font color=''green''>普通云盘</font>]<br>[ephemeral_ssd: <font color=''green''>本地SSD盘</font>]'
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
LocaleKey: DiskCategory
InstanceType: ${EcsInstanceType}
ZoneId: ${VSwitchZoneId1}
InstancePassword:
Type: String
Label:
en: Instance Password
zh-cn: 实例密码
Description:
en: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
ConstraintDescription:
en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
AssociationProperty: ALIYUN::ECS::Instance::Password
AllowedPattern: ^[a-zA-Z0-9-\(\)\`\~\!\@\#\$\%\^\&\*\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?\/]*$
MinLength: 8
MaxLength: 30
NoEcho: true
CreateDNSRecord:
Type: Boolean
Label:
en: Setting domain name resolution
zh-cn: 是否设置域名解析
Description:
en: Whether to set domain name resolution (optional).
zh-cn: 是否设置域名解析(可选)。
Default: false
DomainName:
Type: String
Label:
en: Domain Name
zh-cn: 域名
Description:
en: Domain Name,fill in the applied domain name.
zh-cn: 域名,填入已申请的域名名称。
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${CreateDNSRecord}
- true
Default: ''
Conditions:
IsCreateManageEnv:
Fn::Equals:
- Ref: CreateDNSRecord
- true
Resources:
EcsVpc:
Type: ALIYUN::ECS::VPC
Properties:
VpcName:
Ref: ALIYUN::StackName
CidrBlock: 192.168.0.0/16
EcsVSwitch1:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: VSwitchZoneId1
VpcId:
Ref: EcsVpc
VSwitchName:
Fn::Join:
- '-'
- - VSwitch1
- StackId
- Ref: ALIYUN::StackId
CidrBlock: 192.168.0.0/24
EcsVSwitch2:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: VSwitchZoneId2
VpcId:
Ref: EcsVpc
VSwitchName:
Fn::Join:
- '-'
- - VSwitch2
- StackId
- Ref: ALIYUN::StackId
CidrBlock: 192.168.1.0/24
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: EcsVpc
SecurityGroupName:
Ref: ALIYUN::StackName
SecurityGroupIngress:
- PortRange: 22/22
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 443/443
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: '-1/-1'
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: icmp
NicType: intranet
- Policy: drop
PortRange: '-1/-1'
Priority: 10
SourceCidrIp: 0.0.0.0/0
IpProtocol: all
NicType: intranet
SecurityGroupEgress:
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
WebServerConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
WebServerWaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Timeout: 1800
Count: 2
Handle:
Ref: WebServerConditionHandle
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Count: 2
Properties:
ZoneId:
Ref: VSwitchZoneId1
VpcId:
Ref: EcsVpc
VSwitchId:
Ref: EcsVSwitch1
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7
InstanceName:
Fn::Join:
- '-'
- - Ref: ALIYUN::StackName
- Ref: ALIYUN::Index
IoOptimized: optimized
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize: 40
MaxAmount: 1
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
AllocatePublicIP: true
InternetMaxBandwidthOut: 20
UserData:
Fn::Sub:
- |-
#!/bin/sh
yum install -y nginx
systemctl start nginx.service
cd /usr/share/nginx/html/
echo 'Hello World! This is ECS0${Index}' > index.html
${CurlCli} -d '{"data" : "Install nginx."}'
- CurlCli:
Fn::GetAtt:
- WebServerConditionHandle
- CurlCli
Index:
Fn::Calculate:
- '{0}+{1}'
- 0
- - 1
- Ref: ALIYUN::Index
LoadBalancer:
Type: ALIYUN::ALB::LoadBalancer
Properties:
LoadBalancerName:
Ref: ALIYUN::StackName
LoadBalancerEdition: Basic
VpcId:
Ref: EcsVpc
LoadBalancerBillingConfig:
PayType: PostPay
ZoneMappings:
- ZoneId:
Ref: VSwitchZoneId1
VSwitchId:
Ref: EcsVSwitch1
- ZoneId:
Ref: VSwitchZoneId2
VSwitchId:
Ref: EcsVSwitch2
AddressType: Internet
ServerGroup:
Type: ALIYUN::ALB::ServerGroup
Properties:
VpcId:
Ref: EcsVpc
ServerGroupType: Instance
Protocol: HTTP
ServerGroupName:
Ref: ALIYUN::StackName
Scheduler: Wrr
HealthCheckConfig:
HealthCheckEnabled: true
StickySessionConfig:
StickySessionEnabled: false
BackendServerAttachment:
Type: ALIYUN::ALB::BackendServerAttachment
Count: 2
Properties:
ServerGroupId:
Ref: ServerGroup
Servers:
- ServerType: Ecs
ServerId:
Fn::Select:
- 0
- Fn::Select:
- Ref: ALIYUN::Index
- Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
Port: 80
Weight: 100
Listener:
Type: ALIYUN::ALB::Listener
Properties:
DefaultActions:
- Type: ForwardGroup
ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId:
Ref: ServerGroup
LoadBalancerId:
Ref: LoadBalancer
ListenerProtocol: HTTP
ListenerPort: 80
Domain:
Type: ALIYUN::DNS::Domain
Condition: IsCreateManageEnv
Properties:
DomainName:
Ref: DomainName
DomainRecord:
Type: ALIYUN::DNS::DomainRecord
DependsOn: Domain
Condition: IsCreateManageEnv
Properties:
RR: '@'
DomainName:
Ref: DomainName
Value:
Fn::GetAtt:
- LoadBalancer
- DNSName
Type: CNAME
Outputs:
DNSName:
Description:
en: The domain name of the ALB instance.
zh-cn: ALB实例的域名。
Value:
Fn::Sub:
- http://${DNSName}
- DNSName:
Fn::GetAtt:
- LoadBalancer
- DNSName
InstanceIds:
Description:
en: ECS Instance Ids.
zh-cn: ECS实例ID
Value:
Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- VSwitchZoneId1
- VSwitchZoneId2
Label:
en: Infrastructure Configuration
zh-cn: 基础资源配置
- Parameters:
- EcsInstanceType
- SystemDiskCategory
- EcsImageId
- InstancePassword
Label:
en: ECS Configuration
zh-cn: ECS配置
- Parameters:
- CreateDNSRecord
- DomainName
Label:
en: Domain name resolution configuration
zh-cn: 域名解析配置
TemplateTags:
- acs:document-help:alb:快速实现IPv4服务的负载均衡