diff --git a/charts/aspnetcore/Chart.yaml b/charts/aspnetcore/Chart.yaml index 6e2b392..352b6e1 100644 --- a/charts/aspnetcore/Chart.yaml +++ b/charts/aspnetcore/Chart.yaml @@ -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 diff --git a/charts/aspnetcore/templates/deployment-hpa.yaml b/charts/aspnetcore/templates/deployment-hpa.yaml new file mode 100644 index 0000000..727d892 --- /dev/null +++ b/charts/aspnetcore/templates/deployment-hpa.yaml @@ -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 }} diff --git a/charts/aspnetcore/templates/prechecks.tpl b/charts/aspnetcore/templates/prechecks.tpl new file mode 100644 index 0000000..28fffcc --- /dev/null +++ b/charts/aspnetcore/templates/prechecks.tpl @@ -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 }} diff --git a/charts/aspnetcore/values.yaml b/charts/aspnetcore/values.yaml index 4d60e91..7594d4d 100644 --- a/charts/aspnetcore/values.yaml +++ b/charts/aspnetcore/values.yaml @@ -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