From 0a65be24245d0c3b4f514d794075972a2ac66581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kraus?= Date: Tue, 20 Feb 2024 10:19:00 +0100 Subject: [PATCH] #14 implemented HPA for magento pods --- ci/kind-values.yaml | 2 ++ templates/hpa.yaml | 27 +++++++++++++++++++++++++++ values.yaml | 29 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 templates/hpa.yaml diff --git a/ci/kind-values.yaml b/ci/kind-values.yaml index 4cbff4a..d33ead0 100644 --- a/ci/kind-values.yaml +++ b/ci/kind-values.yaml @@ -2,6 +2,8 @@ magento: podDisruptionBudget: enabled: true + horizontalPodAutoscaler: + enabled: true opensearch: extraEnvs: diff --git a/templates/hpa.yaml b/templates/hpa.yaml new file mode 100644 index 0000000..1dba1a5 --- /dev/null +++ b/templates/hpa.yaml @@ -0,0 +1,27 @@ +{{- if .Values.magento.horizontalPodAutoscaler.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "magento.name" . }} + labels: + {{- include "magento.labels" . | nindent 4 }} + {{- range $key, $val := ($.Values.magento.labels | default dict) }} + {{ $key }}: {{ $val | quote }} + {{- end }} +spec: + scaleTargetRef: + kind: Deployment + name: {{ include "magento.name" . }} + apiVersion: apps/v1 + {{- with .Values.magento.horizontalPodAutoscaler }} + minReplicas: {{ .minCount | default 1 }} + maxReplicas: {{ .maxCount | default 3 }} + behavior: + scaleUp: + {{- toYaml .scaleUp | nindent 6 }} + scaleDown: + {{- toYaml .scaleDown | nindent 6 }} + metrics: + {{- toYaml .metrics | nindent 4 }} + {{- end }} +{{- end }} diff --git a/values.yaml b/values.yaml index 22292b6..e8214fa 100755 --- a/values.yaml +++ b/values.yaml @@ -61,11 +61,40 @@ magento: maxSurge: 100% maxUnavailable: 0 type: RollingUpdate + podDisruptionBudget: enabled: false minAvailable: 0 maxUnavailable: 1 + # HPA configuration, see https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#configurable-scaling-behavior + horizontalPodAutoscaler: + enabled: false + minCount: 1 + maxCount: 3 + + scaleUp: + policies: + - type: Pods + value: 1 + periodSeconds: 60 + stabilizationWindowSeconds: 300 + + scaleDown: + policies: + - type: Pods + value: 1 + periodSeconds: 60 + stabilizationWindowSeconds: 300 + + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 80 + podSecurityContext: {} securityContext: {} tolerations: []