From 1d499d0b68fa46626e2686fbd92a6680e7845e4e Mon Sep 17 00:00:00 2001 From: Simple-Analysis <74850112+Simple-Analysis@users.noreply.github.com> Date: Tue, 2 Apr 2024 09:43:30 -0600 Subject: [PATCH] Add support for memory utilization in HorizontalPodAutoscaler (#530) * Signed-off-by: Simple-Analysis 4850112+Simple-Analysis@users.noreply.github.com Add support for memory utilization in HorizontalPodAutoscaler Signed-off-by: calvin * Update charts/opensearch-dashboards/CHANGELOG.md Signed-off-by: Simple-Analysis <74850112+Simple-Analysis@users.noreply.github.com> * Update README.md - Added autoscaling notes Signed-off-by: Simple-Analysis <74850112+Simple-Analysis@users.noreply.github.com> * Update charts/opensearch-dashboards/Chart.yaml Signed-off-by: Simple-Analysis <74850112+Simple-Analysis@users.noreply.github.com> --------- Signed-off-by: calvin Signed-off-by: Simple-Analysis <74850112+Simple-Analysis@users.noreply.github.com> Co-authored-by: calvin --- charts/opensearch-dashboards/CHANGELOG.md | 12 ++++++- charts/opensearch-dashboards/Chart.yaml | 2 +- charts/opensearch-dashboards/README.md | 6 +++- .../templates/_helpers.tpl | 15 ++++++++ .../templates/autoscaler.yaml | 34 +++++++++++++++++-- charts/opensearch-dashboards/values.yaml | 4 ++- 6 files changed, 66 insertions(+), 7 deletions(-) diff --git a/charts/opensearch-dashboards/CHANGELOG.md b/charts/opensearch-dashboards/CHANGELOG.md index 1fba9bb2..afcf8197 100644 --- a/charts/opensearch-dashboards/CHANGELOG.md +++ b/charts/opensearch-dashboards/CHANGELOG.md @@ -13,9 +13,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Security --- +## [2.16.1] +### Added +- Support for newer HorizontalPodAutoscaler api in Dashboards +- Ability to configure HorizontalPodAutoscaler to use memory as a metric source type +### Changed +### Deprecated +### Removed +### Fixed +### Security +--- ## [2.16.0] ### Added -- Updated OpenSearch Dashboards appVersion to 2.12.0 +- Updated OpenSearch Dashboards appVersion to 2.12.0 ### Changed ### Deprecated ### Removed diff --git a/charts/opensearch-dashboards/Chart.yaml b/charts/opensearch-dashboards/Chart.yaml index a1242a5f..f28d0f03 100644 --- a/charts/opensearch-dashboards/Chart.yaml +++ b/charts/opensearch-dashboards/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 2.16.0 +version: 2.16.1 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/opensearch-dashboards/README.md b/charts/opensearch-dashboards/README.md index ebd356bd..ed0b0740 100644 --- a/charts/opensearch-dashboards/README.md +++ b/charts/opensearch-dashboards/README.md @@ -78,7 +78,11 @@ | `topologySpreadConstraints` | Configuration for pod [topologySpreadConstraints][] | `[]` | | `updateStrategy` | The [updateStrategy][] for the StatefulSet. By default Kubernetes will wait for the cluster to be green after upgrading each pod. Setting this to `OnDelete` will allow you to manually delete each pod during upgrades | `RollingUpdate` | | `extraObjects` | Array of extra K8s manifests to deploy | list `[]` | -| `autoscaling` | Prerequisite: Install/Configure metrics server, to install use `kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml`, See https://github.com/kubernetes-sigs/metrics-server. Configurable pod autoscaling stratergy to scale based on `targetCPUUtilizationPercentage`, configure `minReplicas` and `maxReplicas` for desired scaling | false | +| `autoscaling.enabled` | Prerequisite: Install/Configure metrics server, to install use `kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml`, See https://github.com/kubernetes-sigs/metrics-server. | false | +| `autoscaling.minReplicas` | The lower limit for the number of replicas to which the autoscaler can scale down. | 1 | +| `autoscaling.maxReplicas` | The upper limit for the number of replicas to which the autoscaler can scale up. | 10 | +| `autoscaling.targetCPU` | The target value of the average CPU across all OpenSearch Dashboards pods. | 80 | +| `autoscaling.targetMemory` | The target value of the average memory across all OpenSearch Dashboards pods. Value should be tuned based on the requested memory value for OpenSearch Dashboards pods. Scaling based on memory utilization may be necessary for large datasets or complex dashboards. | 80 | | `livenessProbe` | Configuration fields for the liveness [probe][] | see [exampleLiveness][] in `values.yaml`| | `readinessProbe` | Configuration fields for the readiness [probe][] | see [exampleReadiness][] in `values.yaml`| | `startupProbe` | Configuration fields for the startup [probe][] | see [exampleStartup][] in `values.yaml` | diff --git a/charts/opensearch-dashboards/templates/_helpers.tpl b/charts/opensearch-dashboards/templates/_helpers.tpl index 6c4b60ba..a51f4ec0 100644 --- a/charts/opensearch-dashboards/templates/_helpers.tpl +++ b/charts/opensearch-dashboards/templates/_helpers.tpl @@ -74,6 +74,21 @@ Return the appropriate apiVersion for ingress. {{- end -}} {{- end -}} +{{/* +Return the appropriate apiVersion for Horizontal Pod Autoscaler. +*/}} +{{- define "opensearch-dashboards.hpa.apiVersion" -}} +{{- if $.Capabilities.APIVersions.Has "autoscaling/v2/HorizontalPodAutoscaler" }} +{{- print "autoscaling/v2" }} +{{- else if $.Capabilities.APIVersions.Has "autoscaling/v2beta2/HorizontalPodAutoscaler" }} +{{- print "autoscaling/v2beta2" }} +{{- else if $.Capabilities.APIVersions.Has "autoscaling/v2beta1/HorizontalPodAutoscaler" }} +{{- print "autoscaling/v2beta1" }} +{{- else }} +{{- print "autoscaling/v1" }} +{{- end }} +{{- end }} + {{/* Return if ingress is stable. */}} diff --git a/charts/opensearch-dashboards/templates/autoscaler.yaml b/charts/opensearch-dashboards/templates/autoscaler.yaml index be628442..ff054d39 100644 --- a/charts/opensearch-dashboards/templates/autoscaler.yaml +++ b/charts/opensearch-dashboards/templates/autoscaler.yaml @@ -1,5 +1,5 @@ {{- if .Values.autoscaling.enabled -}} -apiVersion: autoscaling/v1 +apiVersion: {{ include "opensearch-dashboards.hpa.apiVersion" . }} kind: HorizontalPodAutoscaler metadata: name: {{ template "opensearch-dashboards.fullname" . }}-hpa @@ -11,5 +11,33 @@ spec: apiVersion: apps/v1 kind: Deployment name: {{ template "opensearch-dashboards.fullname" . }} - targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} -{{- end }} \ No newline at end of file + {{- if eq (include "opensearch-dashboards.hpa.apiVersion" .) "autoscaling/v1" }} + targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage | default .Values.autoscaling.targetCPU }} + {{- else }} + metrics: + {{- if .Values.autoscaling.targetMemory }} + - type: Resource + resource: + name: memory + {{- if eq (include "opensearch-dashboards.hpa.apiVersion" .) "autoscaling/v2beta1" }} + targetAverageUtilization: {{ .Values.autoscaling.targetMemory }} + {{- else }} + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemory }} + {{- end }} + {{- end }} + {{- if or .Values.autoscaling.targetCPU .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + {{- if eq (include "opensearch-dashboards.hpa.apiVersion" .) "autoscaling/v2beta1" }} + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage | default .Values.autoscaling.targetCPU }} + {{- else }} + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage | default .Values.autoscaling.targetCPU }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/opensearch-dashboards/values.yaml b/charts/opensearch-dashboards/values.yaml index 524031b4..40fece82 100644 --- a/charts/opensearch-dashboards/values.yaml +++ b/charts/opensearch-dashboards/values.yaml @@ -199,7 +199,9 @@ autoscaling: enabled: false minReplicas: 1 maxReplicas: 10 - targetCPUUtilizationPercentage: 80 + # The legacy `targetCPUUtilizationPercentage` key has been deprecated in favor of `targetCPU` + targetCPU: "80" + targetMemory: "80" updateStrategy: type: "Recreate"