forked from ruvnet/RuView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhpa.yaml
More file actions
324 lines (317 loc) · 6.91 KB
/
hpa.yaml
File metadata and controls
324 lines (317 loc) · 6.91 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
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: wifi-densepose-hpa
namespace: wifi-densepose
labels:
app: wifi-densepose
component: autoscaler
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: wifi-densepose
minReplicas: 3
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
- type: Pods
pods:
metric:
name: websocket_connections_per_pod
target:
type: AverageValue
averageValue: "50"
- type: Object
object:
metric:
name: nginx_ingress_controller_requests_rate
describedObject:
apiVersion: v1
kind: Service
name: nginx-service
target:
type: Value
value: "1000"
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60
- type: Pods
value: 2
periodSeconds: 60
selectPolicy: Min
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Percent
value: 50
periodSeconds: 60
- type: Pods
value: 4
periodSeconds: 60
selectPolicy: Max
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: nginx-hpa
namespace: wifi-densepose
labels:
app: wifi-densepose
component: nginx-autoscaler
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 70
- type: Object
object:
metric:
name: nginx_http_requests_per_second
describedObject:
apiVersion: v1
kind: Service
name: nginx-service
target:
type: Value
value: "500"
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 20
periodSeconds: 60
selectPolicy: Min
scaleUp:
stabilizationWindowSeconds: 30
policies:
- type: Percent
value: 100
periodSeconds: 30
- type: Pods
value: 2
periodSeconds: 30
selectPolicy: Max
---
# Vertical Pod Autoscaler for database optimization
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: postgres-vpa
namespace: wifi-densepose
labels:
app: wifi-densepose
component: postgres-vpa
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: postgres
updatePolicy:
updateMode: "Auto"
resourcePolicy:
containerPolicies:
- containerName: postgres
minAllowed:
cpu: 250m
memory: 512Mi
maxAllowed:
cpu: 2
memory: 4Gi
controlledResources: ["cpu", "memory"]
controlledValues: RequestsAndLimits
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: redis-vpa
namespace: wifi-densepose
labels:
app: wifi-densepose
component: redis-vpa
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: redis
updatePolicy:
updateMode: "Auto"
resourcePolicy:
containerPolicies:
- containerName: redis
minAllowed:
cpu: 100m
memory: 256Mi
maxAllowed:
cpu: 1
memory: 2Gi
controlledResources: ["cpu", "memory"]
controlledValues: RequestsAndLimits
---
# Pod Disruption Budget for high availability
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: wifi-densepose-pdb
namespace: wifi-densepose
labels:
app: wifi-densepose
component: pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: wifi-densepose
component: api
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: nginx-pdb
namespace: wifi-densepose
labels:
app: wifi-densepose
component: nginx-pdb
spec:
minAvailable: 1
selector:
matchLabels:
app: wifi-densepose
component: nginx
---
# Custom Resource for advanced autoscaling (KEDA)
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: wifi-densepose-keda-scaler
namespace: wifi-densepose
labels:
app: wifi-densepose
component: keda-scaler
spec:
scaleTargetRef:
name: wifi-densepose
pollingInterval: 30
cooldownPeriod: 300
idleReplicaCount: 3
minReplicaCount: 3
maxReplicaCount: 50
fallback:
failureThreshold: 3
replicas: 6
advanced:
restoreToOriginalReplicaCount: true
horizontalPodAutoscalerConfig:
name: wifi-densepose-keda-hpa
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Percent
value: 50
periodSeconds: 60
triggers:
- type: prometheus
metadata:
serverAddress: http://prometheus-service.monitoring.svc.cluster.local:9090
metricName: wifi_densepose_active_connections
threshold: '80'
query: sum(wifi_densepose_websocket_connections_active)
- type: prometheus
metadata:
serverAddress: http://prometheus-service.monitoring.svc.cluster.local:9090
metricName: wifi_densepose_request_rate
threshold: '1000'
query: sum(rate(http_requests_total{service="wifi-densepose"}[5m]))
- type: prometheus
metadata:
serverAddress: http://prometheus-service.monitoring.svc.cluster.local:9090
metricName: wifi_densepose_queue_length
threshold: '100'
query: sum(wifi_densepose_processing_queue_length)
- type: redis
metadata:
address: redis-service.wifi-densepose.svc.cluster.local:6379
listName: processing_queue
listLength: '50'
passwordFromEnv: REDIS_PASSWORD
---
# Network Policy for autoscaling components
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: autoscaling-network-policy
namespace: wifi-densepose
labels:
app: wifi-densepose
component: autoscaling-network-policy
spec:
podSelector:
matchLabels:
app: wifi-densepose
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: kube-system
- namespaceSelector:
matchLabels:
name: monitoring
ports:
- protocol: TCP
port: 8080
egress:
- to:
- namespaceSelector:
matchLabels:
name: monitoring
ports:
- protocol: TCP
port: 9090
- to:
- podSelector:
matchLabels:
component: redis
ports:
- protocol: TCP
port: 6379