Skip to content

Commit

Permalink
Add support for memory utilization in HorizontalPodAutoscaler (#530)
Browse files Browse the repository at this point in the history
* Signed-off-by: Simple-Analysis [email protected]

Add support for memory utilization in HorizontalPodAutoscaler

Signed-off-by: calvin <[email protected]>

* Update charts/opensearch-dashboards/CHANGELOG.md

Signed-off-by: Simple-Analysis <[email protected]>

* Update README.md - Added autoscaling notes

Signed-off-by: Simple-Analysis <[email protected]>

* Update charts/opensearch-dashboards/Chart.yaml

Signed-off-by: Simple-Analysis <[email protected]>

---------

Signed-off-by: calvin <[email protected]>
Signed-off-by: Simple-Analysis <[email protected]>
Co-authored-by: calvin <[email protected]>
  • Loading branch information
Simple-Analysis and calvin authored Apr 2, 2024
1 parent 0dfa606 commit 1d499d0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
12 changes: 11 additions & 1 deletion charts/opensearch-dashboards/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion charts/opensearch-dashboards/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion charts/opensearch-dashboards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
15 changes: 15 additions & 0 deletions charts/opensearch-dashboards/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/}}
Expand Down
34 changes: 31 additions & 3 deletions charts/opensearch-dashboards/templates/autoscaler.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,5 +11,33 @@ spec:
apiVersion: apps/v1
kind: Deployment
name: {{ template "opensearch-dashboards.fullname" . }}
targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- 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 }}
4 changes: 3 additions & 1 deletion charts/opensearch-dashboards/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1d499d0

Please sign in to comment.