Skip to content

Commit c1b06c9

Browse files
authored
feat: Support autoscaling via HPA (#268)
* feat: expose autoscaling configuration using the HPA resource Signed-off-by: Armel Soro <[email protected]> * Set the Deployment replicas only if autoscaling is not enabled When autoscaling is enabled, the HPA controller controls the number of replicas [1] [1] https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/\#migrating-deployments-and-statefulsets-to-horizontal-autoscaling Signed-off-by: Armel Soro <[email protected]> * Add CI values file with autoscaling enabled Signed-off-by: Armel Soro <[email protected]> * Bump chart version This is a backward-compatible change Signed-off-by: Armel Soro <[email protected]> * Update values schema Signed-off-by: Armel Soro <[email protected]> * Update README Signed-off-by: Armel Soro <[email protected]> --------- Signed-off-by: Armel Soro <[email protected]>
1 parent 3b72b98 commit c1b06c9

File tree

8 files changed

+129
-3
lines changed

8 files changed

+129
-3
lines changed

charts/backstage/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ sources:
3838
# This is the chart version. This version number should be incremented each time you make changes
3939
# to the chart and its templates, including the app version.
4040
# Versions are expected to follow Semantic Versioning (https://semver.org/)
41-
version: 2.5.3
41+
version: 2.6.0

charts/backstage/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Backstage Helm Chart
33

44
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/backstage)](https://artifacthub.io/packages/search?repo=backstage)
5-
![Version: 2.5.3](https://img.shields.io/badge/Version-2.5.3-informational?style=flat-square)
5+
![Version: 2.6.0](https://img.shields.io/badge/Version-2.6.0-informational?style=flat-square)
66
![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
77

88
A Helm chart for deploying a Backstage application
@@ -117,6 +117,7 @@ Kubernetes: `>= 1.19.0-0`
117117
| backstage.annotations | Additional custom annotations for the `Deployment` resource | object | `{}` |
118118
| backstage.appConfig | Generates ConfigMap and configures it in the Backstage pods | object | `{}` |
119119
| backstage.args | Backstage container command arguments | list | `[]` |
120+
| backstage.autoscaling | Autoscaling configuration. <br /> Ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/ | object | `{"enabled":false,"maxReplicas":100,"minReplicas":1,"targetCPUUtilizationPercentage":80}` |
120121
| backstage.command | Backstage container command | list | `["node","packages/backend"]` |
121122
| backstage.containerPorts | Container ports on the Deployment | object | `{"backend":7007}` |
122123
| backstage.containerSecurityContext | Security settings for a Container. <br /> Ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container | object | `{}` |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
backstage:
2+
autoscaling:
3+
enabled: true
4+
minReplicas: 1
5+
maxReplicas: 3
6+
targetCPUUtilizationPercentage: 75
7+
targetMemoryUtilizationPercentage: 90

charts/backstage/templates/backstage-deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ metadata:
2020
{{- include "common.tplvalues.render" ( dict "value" .Values.backstage.annotations "context" $) | nindent 4 }}
2121
{{- end }}
2222
spec:
23+
{{- if not .Values.backstage.autoscaling.enabled }}
2324
replicas: {{ .Values.backstage.replicas }}
25+
{{- end }}
2426
revisionHistoryLimit: {{ .Values.backstage.revisionHistoryLimit }}
2527
selector:
2628
matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}

charts/backstage/templates/hpa.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{{- if .Values.backstage.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "common.names.fullname" . }}
6+
namespace: {{ .Release.Namespace | quote }}
7+
labels: {{ include "common.labels.standard" . | nindent 4 }}
8+
app.kubernetes.io/component: backstage
9+
{{- if .Values.commonLabels }}
10+
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
11+
{{- end }}
12+
annotations:
13+
{{- if .Values.commonAnnotations }}
14+
{{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
15+
{{- end }}
16+
{{- if .Values.backstage.annotations }}
17+
{{- include "common.tplvalues.render" ( dict "value" .Values.backstage.annotations "context" $) | nindent 4 }}
18+
{{- end }}
19+
spec:
20+
scaleTargetRef:
21+
apiVersion: apps/v1
22+
kind: Deployment
23+
name: {{ include "common.names.fullname" . }}
24+
minReplicas: {{ .Values.backstage.autoscaling.minReplicas }}
25+
maxReplicas: {{ .Values.backstage.autoscaling.maxReplicas }}
26+
metrics:
27+
{{- if .Values.backstage.autoscaling.targetCPUUtilizationPercentage }}
28+
- type: Resource
29+
resource:
30+
name: cpu
31+
target:
32+
type: Utilization
33+
averageUtilization: {{ .Values.backstage.autoscaling.targetCPUUtilizationPercentage }}
34+
{{- end }}
35+
{{- if .Values.backstage.autoscaling.targetMemoryUtilizationPercentage }}
36+
- type: Resource
37+
resource:
38+
name: memory
39+
target:
40+
type: Utilization
41+
averageUtilization: {{ .Values.backstage.autoscaling.targetMemoryUtilizationPercentage }}
42+
{{- end }}
43+
{{- end }}

charts/backstage/values.schema.json

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,38 @@
792792
"title": "Backstage container command arguments",
793793
"type": "array"
794794
},
795+
"autoscaling": {
796+
"additionalProperties": false,
797+
"properties": {
798+
"enabled": {
799+
"default": false,
800+
"description": "Enable autoscaling",
801+
"title": "Backstage Autoscaling",
802+
"type": "boolean"
803+
},
804+
"maxReplicas": {
805+
"default": 100,
806+
"title": "Maximum number of Backstage pod replicas that the autoscaler is allowed to scale up to",
807+
"type": "integer"
808+
},
809+
"minReplicas": {
810+
"default": 1,
811+
"title": "Minimum number of Backstage pod replicas that the autoscaler is allowed to scale down to",
812+
"type": "integer"
813+
},
814+
"targetCPUUtilizationPercentage": {
815+
"default": 80,
816+
"title": "Percentage of CPU that each Backstage pod should be using on average before the autoscaler decides to scale",
817+
"type": "integer"
818+
},
819+
"targetMemoryUtilizationPercentage": {
820+
"title": "Percentage of memory that each Backstage pod should be using on average before the autoscaler decides to scale",
821+
"type": "integer"
822+
}
823+
},
824+
"title": "Autoscaling parameters",
825+
"type": "object"
826+
},
795827
"command": {
796828
"default": [
797829
"node",
@@ -3293,7 +3325,7 @@
32933325
"description": "Represents a Glusterfs mount that lasts the lifetime of a pod. Glusterfs volumes do not support ownership management or SELinux relabeling.",
32943326
"properties": {
32953327
"endpoints": {
3296-
"description": "endpoints is the endpoint name that details Glusterfs topology. More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod",
3328+
"description": "endpoints is the endpoint name that details Glusterfs topology.",
32973329
"type": "string"
32983330
},
32993331
"path": {

charts/backstage/values.schema.tmpl.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,38 @@
275275
}
276276
}
277277
},
278+
"autoscaling": {
279+
"title": "Autoscaling parameters",
280+
"type": "object",
281+
"additionalProperties": false,
282+
"properties": {
283+
"enabled": {
284+
"description": "Enable autoscaling",
285+
"title": "Backstage Autoscaling",
286+
"type": "boolean",
287+
"default": false
288+
},
289+
"minReplicas": {
290+
"title": "Minimum number of Backstage pod replicas that the autoscaler is allowed to scale down to",
291+
"type": "integer",
292+
"default": 1
293+
},
294+
"maxReplicas": {
295+
"title": "Maximum number of Backstage pod replicas that the autoscaler is allowed to scale up to",
296+
"type": "integer",
297+
"default": 100
298+
},
299+
"targetCPUUtilizationPercentage": {
300+
"title": "Percentage of CPU that each Backstage pod should be using on average before the autoscaler decides to scale",
301+
"type": "integer",
302+
"default": 80
303+
},
304+
"targetMemoryUtilizationPercentage": {
305+
"title": "Percentage of memory that each Backstage pod should be using on average before the autoscaler decides to scale",
306+
"type": "integer"
307+
}
308+
}
309+
},
278310
"pdb": {
279311
"title": "PDB parameters",
280312
"type": "object",

charts/backstage/values.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ backstage:
140140
minAvailable: ""
141141
maxUnavailable: ""
142142

143+
# -- Autoscaling configuration.
144+
# <br /> Ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
145+
autoscaling:
146+
enabled: false
147+
minReplicas: 1
148+
maxReplicas: 100
149+
targetCPUUtilizationPercentage: 80
150+
# targetMemoryUtilizationPercentage: 80
151+
143152
# -- Container ports on the Deployment
144153
containerPorts:
145154
backend: 7007

0 commit comments

Comments
 (0)