Skip to content

Commit d48d40e

Browse files
Infusibleserhii.hondaruk
andauthored
FEATURE/MINOR: haproxy: Add HPA Keda, improvements ServiceMonitor/deployment (#142)
* add HPA keda * add interval: 30s Co-authored-by: serhii.hondaruk <[email protected]>
1 parent 034d133 commit d48d40e

File tree

5 files changed

+86
-9
lines changed

5 files changed

+86
-9
lines changed

haproxy/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ metadata:
2626
{{ toYaml .Values.podAnnotations | indent 4 }}
2727
{{- end }}
2828
spec:
29-
{{- if not .Values.autoscaling.enabled }}
29+
{{- if and (not .Values.autoscaling.enabled) (not .Values.keda.enabled) }}
3030
replicas: {{ .Values.replicaCount }}
3131
{{- end }}
3232
selector:

haproxy/templates/hpa.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/}}
1616

17-
{{- if .Values.autoscaling.enabled }}
17+
{{- if and (eq .Values.kind "Deployment") .Values.autoscaling.enabled }}
18+
{{- if not .Values.keda.enabled }}
1819
apiVersion: autoscaling/v2beta1
1920
kind: HorizontalPodAutoscaler
2021
metadata:
@@ -45,3 +46,4 @@ spec:
4546
{{- toYaml . | trim | nindent 4 }}
4647
{{- end }}
4748
{{- end }}
49+
{{- end }}

haproxy/templates/keda.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{{/*
2+
Copyright 2021 HAProxy Technologies LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/}}
16+
17+
{{- if and (eq .Values.kind "Deployment") .Values.keda.enabled }}
18+
apiVersion: keda.sh/v1alpha1
19+
kind: ScaledObject
20+
metadata:
21+
name: {{ include "haproxy.fullname" . }}
22+
labels:
23+
{{- include "haproxy.labels" . | nindent 4 }}
24+
{{- if .Values.keda.scaledObject.annotations }}
25+
annotations: {{ toYaml .Values.keda.scaledObject.annotations | nindent 4 }}
26+
{{- end }}
27+
spec:
28+
scaleTargetRef:
29+
apiVersion: apps/v1
30+
kind: Deployment
31+
name: {{ include "haproxy.fullname" . }}
32+
pollingInterval: {{ .Values.keda.pollingInterval }}
33+
cooldownPeriod: {{ .Values.keda.cooldownPeriod }}
34+
minReplicaCount: {{ .Values.keda.minReplicas }}
35+
maxReplicaCount: {{ .Values.keda.maxReplicas }}
36+
triggers:
37+
{{- with .Values.keda.triggers }}
38+
{{ toYaml . | indent 2 }}
39+
{{ end }}
40+
advanced:
41+
restoreToOriginalReplicaCount: {{ .Values.keda.restoreToOriginalReplicaCount }}
42+
{{- if .Values.keda.behavior }}
43+
horizontalPodAutoscalerConfig:
44+
behavior:
45+
{{ with .Values.keda.behavior -}}
46+
{{ toYaml . | indent 8 }}
47+
{{ end }}
48+
{{- end }}
49+
{{- end }}

haproxy/values.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,30 @@ autoscaling:
388388
# type: Value
389389
# value: 10k
390390

391+
keda:
392+
enabled: false
393+
minReplicas: 2
394+
maxReplicas: 20
395+
pollingInterval: 30
396+
cooldownPeriod: 300
397+
restoreToOriginalReplicaCount: false
398+
scaledObject:
399+
annotations: {}
400+
behavior: {}
401+
# scaleDown:
402+
# stabilizationWindowSeconds: 300
403+
# policies:
404+
# - type: Percent
405+
# value: 100
406+
# periodSeconds: 15
407+
triggers: []
408+
# - type: prometheus
409+
# metadata:
410+
# serverAddress: http://<prometheus-host>:9090
411+
# metricName: haproxy_process_idle_time_percent
412+
# threshold: '50'
413+
# query: avg(100-avg_over_time(haproxy_process_idle_time_percent{container="kubernetes-ingress-controller",service="mytest-kubernetes-ingress"}[2m]))
414+
391415
## Pod Disruption Budget
392416
## Only to be used with Deployment kind
393417
## ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/
@@ -435,9 +459,10 @@ serviceMonitor:
435459
## Specify the endpoints
436460
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/design.md#servicemonitor
437461
endpoints:
438-
- port: prometheus
439-
path: /metrics
440-
scheme: http
462+
- port: prometheus
463+
path: /metrics
464+
scheme: http
465+
interval: 30s
441466

442467
## Configure Ingress
443468
## ref: https://kubernetes.io/docs/concepts/services-networking/ingress/

kubernetes-ingress/values.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ controller:
216216
restoreToOriginalReplicaCount: false
217217
scaledObject:
218218
annotations: {}
219-
behaviour: {}
219+
behavior: {}
220220
# scaleDown:
221221
# stabilizationWindowSeconds: 300
222222
# policies:
@@ -482,9 +482,10 @@ controller:
482482
## Specify the endpoints
483483
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/design.md#servicemonitor
484484
endpoints:
485-
- port: stat
486-
path: /metrics
487-
scheme: http
485+
- port: stat
486+
path: /metrics
487+
scheme: http
488+
interval: 30s
488489

489490
## Default 404 backend
490491
defaultBackend:

0 commit comments

Comments
 (0)