Skip to content

Commit

Permalink
Add HPA to chart (#82)
Browse files Browse the repository at this point in the history
* add optional hpa autoscaler support.

* chart version bump

* disable hpa by default

* unnested autoscaling

* miss understood the comment

* Update charts/aspnetcore/templates/deployment-hpa.yaml

Co-authored-by: Guillaume Caya-Letourneau <[email protected]>

* use prechecks instead of calculating them in templates

* removed nullcheck for default value in template

---------

Co-authored-by: Guillaume Caya-Letourneau <[email protected]>
  • Loading branch information
Pycnomerus and Gcaya authored Dec 9, 2024
1 parent 39f55a4 commit 321746d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/aspnetcore/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: aspnetcore
description: A generic Helm chart for ASP.NET Core services
version: 2.2.0
version: 2.3.0
home: https://github.com/gsoft-inc/gsoft-helm-charts
sources:
- https://github.com/gsoft-inc/gsoft-helm-charts
Expand Down
29 changes: 29 additions & 0 deletions charts/aspnetcore/templates/deployment-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if ((.Values.autoscaling).enabled) }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ default (printf "%s-hpa" .Release.Name) .Values.autoscaling.name }}
labels:
{{- include "aspnetcore.standardLabels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- toYaml .Values.commonLabels | nindent 4 }}
{{- end }}
annotations:
{{- with .Values.commonAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
metrics:
- resource:
name: cpu
target:
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
type: Utilization
type: Resource
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ default (printf "%s-deployment" .Release.Name) .Values.deployment.name }}
{{- end }}
9 changes: 9 additions & 0 deletions charts/aspnetcore/templates/prechecks.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- if .Values.autoscaling.enabled }}
{{- if not .Values.autoscaling.minReplicas }}
{{- fail "autoscaling.minReplicas is required" }}
{{- else}}
{{- if le (int .Values.autoscaling.minReplicas) (int .Values.podDisruptionBudget.minAvailable) }}
{{- fail "autoscaling.minReplicas cannot be less than podDisruptionBudget.minAvailable" }}
{{- end }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/aspnetcore/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ azureWorkloadIdentity:
podDisruptionBudget:
minAvailable: 1

## Autoscaling deployment settings
## ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
## @param autoscaling.enabled Default to false. Enable autoscaling
## @param autoscaling.minReplicas Optional if PodDistributionBudget is set. Minimum number of ASP.NET Core replicas minimum is PodDisruptionBudget.minAvailable + 1
## @param autoscaling.maxReplicas Optional if PodDistributionBudget is set or minReplicas is set. Maximum number of ASP.NET Core replicas minimum is minReplicas value.
## @param autoscaling.targetCPUUtilizationPercentage Target CPU utilization percentage for autoscaling
autoscaling:
enabled: true
name: ""
minReplicas: 2
maxReplicas: 3
targetCPUUtilizationPercentage: 80

## @param extraVolumes Optionally specify extra list of additional volumes, e.g:
## extraVolumes:
## - name: config-vol
Expand Down

0 comments on commit 321746d

Please sign in to comment.