-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeploy.yml
550 lines (505 loc) · 11.9 KB
/
deploy.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
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
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: external-load-balancer
namespace: default
spec:
gatewayClassName: gke-l7-gxlb
listeners:
- name: http
protocol: HTTP
port: 80
---
kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: http-route
namespace: default
labels:
gateway: external-load-balancer
spec:
parentRefs:
- name: external-load-balancer
rules:
- backendRefs:
- name: nginx-service
port: 80
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
default.conf: |
upstream backend-web {
server flask-app-service:5000;
}
upstream frontend-web {
server react-app-service:3000;
}
server {
listen 80;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location /api/ {
proxy_pass http://backend-web;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location /init { # remove this block after initialization
proxy_pass http://backend-web;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location / { # External Load Balancer requires this path for health check
proxy_pass http://frontend-web;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: nginx-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx
minReplicas: 1
maxReplicas: 3
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 20
periodSeconds: 15
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 80
periodSeconds: 15
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: default
spec:
replicas: 1 # number of pods at the start
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
resources:
requests:
cpu: 200m
memory: 200Mi
limits:
cpu: 400m
memory: 400Mi
volumeMounts:
- name: config
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
volumes:
- name: config
configMap:
name: nginx-config
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:latest
ports:
- containerPort: 6379
volumeMounts:
- name: config
mountPath: /usr/local/etc/redis/redis.conf
subPath: redis.conf
args:
- redis-server
- /usr/local/etc/redis/redis.conf
volumes:
- name: config
configMap:
name: redis-config
---
apiVersion: v1
kind: Service
metadata:
name: redis-service
spec:
selector:
app: redis
ports:
- protocol: TCP
port: 6379
targetPort: 6379
type: ClusterIP
---
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-config
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: flask-app-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: flask-app
minReplicas: 1
maxReplicas: 3
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 20
periodSeconds: 15
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 80
periodSeconds: 15
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-app
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: flask-app
template:
metadata:
labels:
app: flask-app
spec:
containers:
- name: flask-app
image: <DOCKER_IMAGE_OF_FLASK_APP> # replace with docker_image:tag
ports:
- containerPort: 5000
env:
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: environment-variables
key: SECRET_KEY
- name: MYSQL_HOST
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_HOST
- name: MYSQL_PORT
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_PORT
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_USER
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_PASSWORD
- name: MYSQL_ADMIN_ACCOUNT
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_ADMIN_ACCOUNT
- name: MYSQL_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_ADMIN_PASSWORD
- name: MYSQL_STAFF_ACCOUNT
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_STAFF_ACCOUNT
- name: MYSQL_STAFF_PASSWORD
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_STAFF_PASSWORD
- name: MYSQL_REGISTERED_USER_ACCOUNT
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_REGISTERED_USER_ACCOUNT
- name: MYSQL_REGISTERED_USER_PASSWORD
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_REGISTERED_USER_PASSWORD
- name: MYSQL_GUEST_USER_ACCOUNT
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_GUEST_USER_ACCOUNT
- name: MYSQL_GUEST_USER_PASSWORD
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_GUEST_USER_PASSWORD
- name: MYSQL_DB
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_DB
- name: REDIS_HOST
valueFrom:
secretKeyRef:
name: environment-variables
key: REDIS_HOST
- name: REDIS_PORT
valueFrom:
secretKeyRef:
name: environment-variables
key: REDIS_PORT
- name: INIT_ENABLED
valueFrom:
secretKeyRef:
name: environment-variables
key: INIT_ENABLED
resources:
requests:
cpu: 400m
memory: 400Mi
limits:
cpu: 800m
memory: 800Mi
---
apiVersion: v1
kind: Service
metadata:
name: flask-app-service
spec:
selector:
app: flask-app
ports:
- protocol: TCP
port: 5000
targetPort: 5000
type: ClusterIP
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
namespace: default
spec:
serviceName: mysql-service
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:latest
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_PASSWORD
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_DB
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: environment-variables
key: MYSQL_PASSWORD
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumeClaimTemplates:
- metadata:
name: mysql-persistent-storage
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 6Gi
limits:
storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
selector:
app: mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306
type: ClusterIP
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: react-app-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: react-app
minReplicas: 1
maxReplicas: 2
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 20
periodSeconds: 15
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 80
periodSeconds: 15
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: react-app
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: react-app
template:
metadata:
labels:
app: react-app
spec:
containers:
- name: react-app
image: <DOCKER_IMAGE_OF_REACT_APP> # replace with docker_image:tag
ports:
- containerPort: 3000
env:
- name: REACT_APP_BACKEND_API_URL
valueFrom:
secretKeyRef:
name: environment-variables
key: BACKEND_API_URL
resources:
requests:
cpu: 400m
memory: 400Mi
limits:
cpu: 800m
memory: 800Mi
---
apiVersion: v1
kind: Service
metadata:
name: react-app-service
spec:
selector:
app: react-app
ports:
- protocol: TCP
port: 3000
targetPort: 3000
type: ClusterIP
---
apiVersion: v1
kind: Secret
metadata:
name: environment-variables
type: Opaque
stringData:
SECRET_KEY: "<SECRET_KEY>"
MYSQL_HOST: "mysql-service" # service name of mysql
MYSQL_PORT: "3306"
MYSQL_USER: "root"
MYSQL_PASSWORD: "<MYSQL_ROOT_PASSWORD>" # replace with mysql password
MYSQL_ADMIN_ACCOUNT: "adminAccount"
MYSQL_ADMIN_PASSWORD: "<MYSQL_ADMIN_PASSWORD>" # replace with admin password in init script
MYSQL_STAFF_ACCOUNT: "staffAccount"
MYSQL_STAFF_PASSWORD: "<MYSQL_STAFF_PASSWORD>" # replace with staff password in init script
MYSQL_REGISTERED_USER_ACCOUNT: "registeredUserAccount"
MYSQL_REGISTERED_USER_PASSWORD: "<MYSQL_REGISTERED_USER_PASSWORD>" # replace with registered user password in init script
MYSQL_GUEST_USER_ACCOUNT: "guestAccount"
MYSQL_GUEST_USER_PASSWORD: "<MYSQL_GUEST_USER_PASSWORD>" # replace with guest user password in init script
MYSQL_DB: "<MYSQL_DATABASE_NAME>" # replace with database name
REDIS_HOST: "redis-service" # service name of redis
REDIS_PORT: "6379"
INIT_ENABLED: "1" # after initialization, change to "0" and re-deploy
BACKEND_API_URL: "http://www.b-airlines.online/api" # replace with backend api url