-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathserverless-high-availability-architecture.yml
More file actions
581 lines (581 loc) · 13.1 KB
/
serverless-high-availability-architecture.yml
File metadata and controls
581 lines (581 loc) · 13.1 KB
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建Serverless高可用架构,包括VPC、交换机、安全组、PolarDB集群、ALB、SAE应用,实现跨可用区部署与自动扩展。
en: Establish a Serverless high-availability architecture comprising Virtual Private
Cloud (VPC), switches, security groups, PolarDB clusters, Application Load Balancers
(ALB), and Serverless App Engine (SAE) applications, facilitating cross-zone deployment
and automatic scaling.
Parameters:
CommonName:
Type: String
Default: serverless
ZoneId1:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
ExclusiveTo:
- ZoneId2
Label:
en: Availability Zone
zh-cn: 可用区1
ZoneId2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
ExclusiveTo:
- ZoneId1
Label:
en: Availability Zone
zh-cn: 可用区2
DBUserName:
Type: String
ConstraintDescription:
en: >-
Consist of 2 to 32 characters of lowercase letters, underline.
Must begin with a letter and be end with an alphanumeric character
zh-cn: >-
由 2 到 32 个小写字母组成,支持小写字母、数字和下划线,以小写字母开头。
Label:
zh-cn: MySQL数据库账号
en: MySQL DB Username
Default: applets
AllowedPattern: '^[a-z][a-z0-9_]{0,31}$'
DBPassword:
NoEcho: true
Type: String
Description:
en: >-
MySQL user password, Length 8-30, must contain three(Capital letters,
lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
symbol in)
zh-cn: >-
数据库账号密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
中的特殊符号)
Label:
en: MySQL Instance Password
zh-cn: MySQL数据库密码
ConstraintDescription:
en: >-
Length 8-30, must contain three(Capital letters, lowercase letters,
numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: '长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符号)'
AssociationProperty: 'ALIYUN::RDS::Instance::AccountPassword'
Resources:
Vpc:
Type: 'ALIYUN::ECS::VPC'
Properties:
CidrBlock: 192.168.0.0/16
VpcName:
Fn::Sub: ${CommonName}-vpc
VSwitch1:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.1.0/24
ZoneId:
Ref: ZoneId1
VSwitchName:
Fn::Sub: ${CommonName}-web-01
VSwitch2:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.2.0/24
ZoneId:
Ref: ZoneId2
VSwitchName:
Fn::Sub: ${CommonName}-web-02
VSwitch3:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.3.0/24
ZoneId:
Ref: ZoneId1
VSwitchName:
Fn::Sub: ${CommonName}-db-01
VSwitch4:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.4.0/24
ZoneId:
Ref: ZoneId1
VSwitchName:
Fn::Sub: ${CommonName}-pub-01
VSwitch5:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.5.0/24
ZoneId:
Ref: ZoneId2
VSwitchName:
Fn::Sub: ${CommonName}-pub-02
SecurityGroup:
Type: 'ALIYUN::ECS::SecurityGroup'
Properties:
VpcId:
Ref: Vpc
SecurityGroupName:
Fn::Sub: ${CommonName}-sg
SecurityGroupIngress:
- PortRange: 443/443
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 80/80
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 3306/3306
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
PolarDBCluster:
Type: 'ALIYUN::POLARDB::DBCluster'
Properties:
VpcId:
Ref: Vpc
DBType: MySQL
ClusterNetworkType: VPC
ZoneId:
Ref: ZoneId1
SecurityGroupIds:
- Ref: SecurityGroup
DBVersion: '8.0'
DBMinorVersion: '8.0.2'
DBNodeClass: polar.mysql.sl.small
VSwitchId:
Ref: VSwitch3
CreationCategory: Normal
ScaleRoNumMin: 1
ScaleRoNumMax: 4
ScaleMin: 1
ScaleMax: 16
ProxyType: GENERAL
PayType: Postpaid
ServerlessType: AgileServerless
PolarDBDatabase:
Type: 'ALIYUN::POLARDB::DBInstance'
Properties:
DBClusterId:
Ref: PolarDBCluster
CharacterSetName: utf8mb4
DBName: applets
DBDescription: serverless demo
PolarDBAccount:
Type: 'ALIYUN::POLARDB::Account'
Properties:
DBClusterId:
Ref: PolarDBCluster
AccountName:
Ref: DBUserName
AccountType: Normal
AccountPassword:
Ref: DBPassword
AccountPrivilege: ReadWrite
DBName:
Ref: PolarDBDatabase
ALB:
Type: 'ALIYUN::ALB::LoadBalancer'
Properties:
LoadBalancerName:
Fn::Sub: ${CommonName}-alb
LoadBalancerEdition: Basic
VpcId:
Ref: Vpc
LoadBalancerBillingConfig:
PayType: PostPay
AddressType: Internet
AddressAllocatedMode: Fixed
ZoneMappings:
- ZoneId:
Ref: ZoneId1
VSwitchId:
Ref: VSwitch1
- ZoneId:
Ref: ZoneId2
VSwitchId:
Ref: VSwitch2
SaeNamespace:
Type: 'ALIYUN::SAE::Namespace'
Properties:
NamespaceName: serverless-demo
NamespaceId:
Fn::Sub:
- '${Region}:serverless${Suffix}'
- Region:
Ref: ALIYUN::Region
Suffix:
Fn::Jq:
- First
- .StackId[:5]
- StackId:
Ref: ALIYUN::StackId
SAE:
Type: 'ALIYUN::SAE::Application'
DependsOn: SaeNamespace
Properties:
AppName:
Fn::Sub:
- 'serverless-demo-${Suffix}'
- Suffix:
Fn::Jq:
- First
- .StackId[:5]
- StackId:
Ref: ALIYUN::StackId
AppDescription: serverless-demo
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: SecurityGroup
VSwitchId:
Fn::Sub: '${VSwitch4},${VSwitch5}'
Replicas: 2
NamespaceId:
Ref: SaeNamespace
Cpu: 2000
Memory: 4096
PackageType: FatJar
PackageVersion: '1718956564756'
Jdk: Open JDK 8
PackageUrl: https://help-static-aliyun-doc.aliyuncs.com/tech-solution/sae-demo-0.0.3.jar
Timezone: Asia/Shanghai
JarStartArgs: '$JAVA_HOME/bin/java $Options -jar $CATALINA_OPTS "$package_path" $args'
JarStartOptions: >-
-XX:+UseContainerSupport
-XX:InitialRAMPercentage=70.0
-XX:MaxRAMPercentage=70.0
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-Xloggc:/home/admin/nas/gc-${POD_IP}-$(date '+%s').log
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/home/admin/nas/dump-${POD_IP}-$(date '+%s').hprof
Envs:
Fn::Sub: >-
[{"name":"APPLETS_MYSQL_ENDPOINT","value":"${PolarDBCluster.PrimaryConnectionString}"},
{"name":"APPLETS_MYSQL_USER","value":"${PolarDBAccount}"},
{"name":"APPLETS_MYSQL_PASSWORD","value":"${DBPassword}"},
{"name":"APPLETS_MYSQL_DB_NAME","value":"applets"},
{"name":"APP_MANUAL_DEPLOY","value":false}]
Readiness: '{"exec":{"command":["sleep","6s"]},"initialDelaySeconds":15,"timeoutSeconds":12}'
Liveness: '{"httpGet":{"path":"/","port":80,"scheme":"HTTP"},"initialDelaySeconds":10,"timeoutSeconds":10,"periodSeconds":10,"successThreshold":1,"failureThreshold":3}'
WaitApp:
Type: 'ALIYUN::ROS::Sleep'
DependsOn: SAE
Properties:
CreateDuration: 180
SaeIngress:
Type: 'ALIYUN::SAE::Ingress'
DependsOn: WaitApp
Properties:
NamespaceId:
Ref: SaeNamespace
Description: serverless-demo-router
LoadBalanceType: alb
SlbId:
Ref: ALB
ListenerProtocol: HTTP
ListenerPort: 80
Rules:
- Domain: example.com
Path: /
AppId:
Ref: SAE
ContainerPort: 80
BackendProtocol: http
DefaultRule:
AppId:
Ref: SAE
ContainerPort: 80
BackendProtocol: http
Outputs:
WebUrl:
Description:
zh-cn: Web 访问地址。
en: Web Addresses
Value:
'Fn::Sub': 'http://${ALB.DNSName}'
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- DBUserName
- DBPassword
- ZoneId1
- ZoneId2
TemplateTags:
- acs:technical-solution:high-availability-architecture:Serverless高可用架构-tech_solu_129
- acs:public_template:Solution:serverless-high-availability-architecture
Hidden:
- CommonName
ALIYUN::ROS::Composer:
'95134821':
Res:
- VSwitch3
Parent: c3ab8a40
Rect:
- 400
- 200
- 1420
- 300
- 5
- 0
c0c9c357:
Rect:
- 1980
- 978
- 40
- 100
- 1
- 0
ResT: Composer::ROSParameter::AlibabaCloud
7ba458e5:
Parent: c0c9c357
Rect:
- 1942
- 912
- 58
- 150
- 2
- 0
ResT: Composer::ROSParameter::Region
2c74c767:
Res:
- Vpc
Parent: 7ba458e5
Rect:
- 1786
- 846
- 74
- 200
- 3
- 0
5bfacbea:
Res:
- PolarDBDatabase
Parent: 7ba458e5
Rect:
- 40
- 40
- 1880
- 431
- 3
- 0
ResT: ALIYUN::POLARDB::DBInstance
696794d8:
Res:
- PolarDBAccount
Parent: 7ba458e5
Rect:
- 40
- 40
- 1880
- 220
- 3
- 0
df158759:
Res:
- SaeNamespace
Parent: 7ba458e5
Rect:
- 40
- 40
- 1940
- 920
- 3
- 0
Hidden: true
47ccca07:
Res:
- WaitApp
Parent: 7ba458e5
Rect:
- 40
- 40
- 80
- 920
- 3
- 0
Hidden: true
cf4ad249:
Res:
- SaeIngress
Parent: 7ba458e5
Rect:
- 40
- 40
- 240
- 800
- 3
- 0
0015c201:
Res:
- SAE
Parent: 2c74c767
Rect:
- 40
- 40
- 542
- 800
- 4
- 0
c3ab8a40:
Res:
- ZoneId1
Parent: 2c74c767
Rect:
- 860
- 490
- 980
- 250
- 4
- 0
ResT: Composer::ROSParameter::Zone
8890b8c7:
Res:
- ZoneId2
Parent: 2c74c767
Rect:
- 860
- 270
- 90
- 421
- 4
- 0
ResT: Composer::ROSParameter::Zone
6397a9be:
Res:
- VSwitch1
Parent: c3ab8a40
Rect:
- 400
- 200
- 1000
- 300
- 5
- 0
33aa0776:
Res:
- VSwitch2
Parent: 8890b8c7
Rect:
- 400
- 200
- 110
- 471
- 5
- 0
f72b511a:
Res:
- VSwitch4
Parent: c3ab8a40
Rect:
- 400
- 200
- 1000
- 520
- 5
- 0
4211a52a:
Res:
- VSwitch5
Parent: 8890b8c7
Rect:
- 400
- 200
- 530
- 471
- 5
- 0
024a524c:
Res:
- PolarDBCluster
Parent: '95134821'
Rect:
- 40
- 40
- 1440
- 350
- 6
- 0
4656da25:
Res:
- ALB
Parent: 33aa0776
Rect:
- 40
- 40
- 240
- 536
- 6
- 0
bfaa4b06:
Res:
- SecurityGroup
Parent: 2c74c767
Rect:
- 160
- 120
- 980
- 760
- 10
- 0
Hidden: true
daa23f8c:
Edge:
- 024a524c
- bfaa4b06
Line: 0:0:0:gray:0
bc9d9573:
Parent: 7ba458e5
Edge:
- 5bfacbea
- 024a524c
Line: 0:0:0:gray:0
2905803a:
Parent: 7ba458e5
Edge:
- 696794d8
- 024a524c
Line: 0:0:0:gray:0
1478551d:
Parent: 7ba458e5
Edge:
- 696794d8
- 5bfacbea
Line: 0:0:0:gray:0
ebb809bf:
Parent: 2c74c767
Edge:
- 0015c201
- bfaa4b06
Line: 0:0:0:gray:0
7d17afd9:
Parent: 7ba458e5
Edge:
- 0015c201
- df158759
Line: 0:0:0:gray:0
d0b953b0:
Parent: 7ba458e5
Edge:
- cf4ad249
- df158759
Line: 0:0:0:gray:0
f5920ca1:
Parent: 7ba458e5
Edge:
- cf4ad249
- 4656da25
Line: 0:0:0:gray:0
db541cb6:
Parent: 7ba458e5
Edge:
- cf4ad249
- 0015c201
Line: 0:0:0:gray:0