-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-nginx01.yaml
331 lines (297 loc) · 7.26 KB
/
service-nginx01.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
325
326
327
328
329
330
##
## https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
##
## https://www.baeldung.com/ops/kubernetes-pod-vs-deployment
# https://kubernetes.io/zh-cn/docs/concepts/services-networking/network-policies/
#
# 1. create app configuration, app container deployment, app sidecar deployment, service, hpa, probes, ingress
# 2. network policy to control ingress to app service
# 3. token policy to authentication access to app service
#
apiVersion: v1
kind: ServiceAccount
metadata:
name: zt-nginx-svc-account
---
#
# JWT Token:
# expire time: None by default
#
apiVersion: v1
kind: Secret
metadata:
name: zt-nginx-secret
annotations:
kubernetes.io/service-account.name: zt-nginx-svc-account
type: kubernetes.io/service-account-token
data:
extra: YmFyCg==
---
apiVersion: v1
kind: ConfigMap
metadata:
name: zt-nginx-configmap
data:
index.html: |
<html>
<body>
<h1>Welcome to My Website in Blue!</h1>
</body>
</html>
zt.conf: |
server {
listen 81;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /health {
return 200;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
sidecar.conf: |
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
#include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name zt.localdev.me;
location / {
proxy_pass http://localhost:81;
}
}
}
# 类属性键;每一个键都映射到一个简单的值
player_initial_lives: "3"
ui_properties_file_name: "user-interface.properties"
# 类文件键
game.properties: |
enemy.types=aliens,monsters
player.maximum-lives=5
user-interface.properties: |
color.good=purple
color.bad=yellow
---
apiVersion: v1
kind: ConfigMap
metadata:
name: zt-app-configmap
data:
PG_PASS: bXlzZWNyZXRwYXNzd29yZA==
PG_HOST: localhost:5379
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: zt-nginx-deployment
labels:
version: v1
spec:
replicas: 2
selector:
matchLabels:
app: zt-nginx-pod
version: v1
template:
metadata:
labels:
app: zt-nginx-pod
version: v1
spec:
serviceAccountName: zt-nginx-svc-account
# sidecar
initContainers:
- name: appdoor
image: nginx:1.10
restartPolicy: Always
#command: ['sh', '-c', 'tail /opt/logs.txt']
volumeMounts:
- name: data
mountPath: /opt
- name: sidecar-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
#
resources:
limits:
cpu: 100m
memory: 100Mi
requests:
cpu: 50m
memory: 50Mi
# main
containers:
- image: nginx:1.10 # Edit this for your reponame
#imagePullPolicy: Never
env:
- name: NGINX_HOST
value: zt.localdev.me
envFrom:
- configMapRef:
name: zt-app-configmap
#
resources:
limits:
cpu: 100m
memory: 100Mi
requests:
cpu: 50m
memory: 50Mi
name: zt-nginx-pod
#restartPolicy: Never
ports:
- containerPort: 81
- name: liveness-port
containerPort: 81
#
volumeMounts:
- name: html-volume
mountPath: /usr/share/nginx/html
- name: nginx-config
mountPath: /etc/nginx/conf.d
#
livenessProbe:
httpGet:
path: /health
port: liveness-port
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
timeoutSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /health
port: liveness-port
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
timeoutSeconds: 10
failureThreshold: 3
startupProbe:
httpGet:
path: /health
port: liveness-port
failureThreshold: 1
periodSeconds: 10
#
volumes:
- name: data
emptyDir: {}
- name: html-volume
# Use either ConfigMap or PersistentVolume
configMap:
name: zt-nginx-configmap
items:
- key: index.html
path: index.html
# persistentVolumeClaim:
# claimName: html-pvc
- name: nginx-config
configMap:
name: zt-nginx-configmap
items:
- key: zt.conf
path: default.conf
- name: sidecar-config
configMap:
name: zt-nginx-configmap
items:
- key: sidecar.conf
path: nginx.conf
- name: access-token
projected:
sources:
# 要为某 Pod 提供一个受众为 vault 并且有效期限为 2 小时的令牌 ??
- serviceAccountToken:
path: access-token
expirationSeconds: 600
audience: vault
---
apiVersion: v1
kind: Service
metadata:
labels:
app: zt-nginx-svc
version: v1
name: zt-nginx-svc
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: zt-nginx-pod
type: ClusterIP
---
# https://docs.openshift.com/container-platform/4.10/nodes/pods/nodes-pods-autoscaling.html
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: hpa-zt-nginx
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: zt-nginx-deployment
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 50
behavior:
scaleDown:
policies:
- type: Pods
value: 4
periodSeconds: 60
- type: Percent
value: 10
periodSeconds: 60
selectPolicy: Min
stabilizationWindowSeconds: 300
scaleUp:
policies:
- type: Pods
value: 5
periodSeconds: 70
- type: Percent
value: 12
periodSeconds: 80
selectPolicy: Max
stabilizationWindowSeconds: 0