forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
serverless-high-availability-architecture.yml
310 lines (310 loc) · 8.51 KB
/
serverless-high-availability-architecture.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Serverless high availability architecture.
zh-cn: Serverless高可用架构。
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: 22/22
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 443/443
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 80/80
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/demos/sae-demo-0.0.1-SNAPSHOT.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"}]
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: The Addresses of Web.
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
Hidden:
- CommonName