Skip to content

Commit 6ad7153

Browse files
committed
feat(helm): add HPA and PDB support for Django and Celery Beat
- Add PodDisruptionBudget for Django pods - Add HorizontalPodAutoscaler for Django pods - Add PodDisruptionBudget for Celery Beat pods - Add HorizontalPodAutoscaler for Celery Beat pods - All resources default to disabled (enabled: false) - Configurable via values.yaml Fixes #13391
1 parent 6fd39a3 commit 6ad7153

File tree

8 files changed

+281
-0
lines changed

8 files changed

+281
-0
lines changed

docs/content/en/open_source/upgrading/2.52.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Additionally, each deployment can specify its own pod and container security con
3232

3333
Now each container can specify the resource requests and limits.
3434

35+
#### New values
36+
37+
Added Helm chart support for Celery Beat and Django for Horizontal Pod Autoscaler using `celery.beat.autoscaling` and `django.autoscaling`. And Pod Disruption Budget using `celery.beat.podDisruptionBudget` and `django.podDisruptionBudget`
38+
3539
#### Moved values
3640

3741
The following Helm chart values have been modified in this release:

helm/defectdojo/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ A Helm chart for Kubernetes to install DefectDojo
529529
| celery.beat.affinity | object | `{}` | |
530530
| celery.beat.annotations | object | `{}` | Annotations for the Celery beat deployment. |
531531
| celery.beat.automountServiceAccountToken | bool | `false` | |
532+
| celery.beat.autoscaling | object | `{"autoscaleBehavior":{},"enabled":false,"maxReplicas":5,"minReplicas":2,"targetCPUUtilizationPercentage":80,"targetMemoryUtilizationPercentage":{}}` | Autoscaling configuration for Celery beat deployment. |
532533
| celery.beat.containerSecurityContext | object | `{}` | Container security context for the Celery beat containers. |
533534
| celery.beat.extraEnv | list | `[]` | Additional environment variables injected to Celery beat containers. |
534535
| celery.beat.extraInitContainers | list | `[]` | A list of additional initContainers to run before celery beat containers. |
@@ -538,6 +539,7 @@ A Helm chart for Kubernetes to install DefectDojo
538539
| celery.beat.livenessProbe | object | `{}` | Enable liveness probe for Celery beat container. ``` exec: command: - bash - -c - celery -A dojo inspect ping -t 5 initialDelaySeconds: 30 periodSeconds: 60 timeoutSeconds: 10 ``` |
539540
| celery.beat.nodeSelector | object | `{}` | |
540541
| celery.beat.podAnnotations | object | `{}` | Annotations for the Celery beat pods. |
542+
| celery.beat.podDisruptionBudget | object | `{"enabled":false,"minAvailable":"50%","unhealthyPodEvictionPolicy":"AlwaysAllow"}` | Configure pod disruption budgets for Celery beat ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget |
541543
| celery.beat.podSecurityContext | object | `{}` | Pod security context for the Celery beat pods. |
542544
| celery.beat.readinessProbe | object | `{}` | Enable readiness probe for Celery beat container. |
543545
| celery.beat.replicas | int | `1` | |
@@ -595,6 +597,7 @@ A Helm chart for Kubernetes to install DefectDojo
595597
| django.affinity | object | `{}` | |
596598
| django.annotations | object | `{}` | |
597599
| django.automountServiceAccountToken | bool | `false` | |
600+
| django.autoscaling | object | `{"autoscaleBehavior":{},"enabled":false,"maxReplicas":5,"minReplicas":2,"targetCPUUtilizationPercentage":80,"targetMemoryUtilizationPercentage":{}}` | Autoscaling configuration for the Django deployment. |
598601
| django.extraEnv | list | `[]` | Additional environment variables injected to all Django containers and initContainers. |
599602
| django.extraInitContainers | list | `[]` | A list of additional initContainers to run before the uwsgi and nginx containers. |
600603
| django.extraVolumeMounts | list | `[]` | Array of additional volume mount points common to all containers and initContainers. |
@@ -622,6 +625,7 @@ A Helm chart for Kubernetes to install DefectDojo
622625
| django.nginx.tls.enabled | bool | `false` | |
623626
| django.nginx.tls.generateCertificate | bool | `false` | |
624627
| django.nodeSelector | object | `{}` | |
628+
| django.podDisruptionBudget | object | `{"enabled":false,"minAvailable":"50%","unhealthyPodEvictionPolicy":"AlwaysAllow"}` | Configure pod disruption budgets for django ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget |
625629
| django.podSecurityContext | object | `{"fsGroup":1001}` | Pod security context for the Django pods. |
626630
| django.replicas | int | `1` | |
627631
| django.service.annotations | object | `{}` | |
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{- if .Values.celery.beat.autoscaling.enabled -}}
2+
{{- $fullName := include "defectdojo.fullname" . -}}
3+
apiVersion: autoscaling/v2
4+
kind: HorizontalPodAutoscaler
5+
metadata:
6+
{{- with mergeOverwrite dict .Values.extraAnnotations .Values.celery.annotations .Values.celery.beat.annotations }}
7+
annotations:
8+
{{- range $key, $value := . }}
9+
{{ $key }}: {{ quote $value }}
10+
{{- end }}
11+
{{- end }}
12+
name: {{ $fullName }}-celery-beat
13+
namespace: {{ .Release.Namespace }}
14+
labels:
15+
defectdojo.org/component: celery
16+
defectdojo.org/subcomponent: beat
17+
app.kubernetes.io/name: {{ include "defectdojo.name" . }}
18+
app.kubernetes.io/instance: {{ .Release.Name }}
19+
app.kubernetes.io/managed-by: {{ .Release.Service }}
20+
helm.sh/chart: {{ include "defectdojo.chart" . }}
21+
{{- range $key, $value := .Values.extraLabels }}
22+
{{ $key }}: {{ quote $value }}
23+
{{- end }}
24+
spec:
25+
scaleTargetRef:
26+
apiVersion: apps/v1
27+
kind: "Deployment"
28+
name: {{ $fullName }}-celery-beat
29+
minReplicas: {{ .Values.celery.beat.autoscaling.minReplicas }}
30+
maxReplicas: {{ .Values.celery.beat.autoscaling.maxReplicas }}
31+
metrics:
32+
{{- with .Values.celery.beat.autoscaling.targetCPUUtilizationPercentage }}
33+
- type: Resource
34+
resource:
35+
name: cpu
36+
target:
37+
averageUtilization: {{ . }}
38+
type: Utilization
39+
{{- end }}
40+
{{- with .Values.celery.beat.autoscaling.targetMemoryUtilizationPercentage }}
41+
- type: Resource
42+
resource:
43+
name: memory
44+
target:
45+
averageUtilization: {{ . }}
46+
type: Utilization
47+
{{- end }}
48+
{{- if .Values.celery.beat.autoscaling.autoscaleBehavior }}
49+
behavior: {{ toYaml .Values.celery.beat.autoscaling.autoscaleBehavior | nindent 4 }}
50+
{{- end }}
51+
{{- end }}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{{- if .Values.celery.beat.podDisruptionBudget.enabled }}
2+
{{- $fullName := include "defectdojo.fullname" . -}}
3+
apiVersion: policy/v1
4+
kind: PodDisruptionBudget
5+
metadata:
6+
{{- with mergeOverwrite dict .Values.extraAnnotations .Values.celery.annotations .Values.celery.beat.annotations }}
7+
annotations:
8+
{{- range $key, $value := . }}
9+
{{ $key }}: {{ quote $value }}
10+
{{- end }}
11+
{{- end }}
12+
labels:
13+
defectdojo.org/component: celery
14+
defectdojo.org/subcomponent: beat
15+
app.kubernetes.io/name: {{ include "defectdojo.name" . }}
16+
app.kubernetes.io/instance: {{ .Release.Name }}
17+
app.kubernetes.io/managed-by: {{ .Release.Service }}
18+
helm.sh/chart: {{ include "defectdojo.chart" . }}
19+
{{- range $key, $value := .Values.extraLabels }}
20+
{{ $key }}: {{ quote $value }}
21+
{{- end }}
22+
name: {{ $fullName }}-celery-beat
23+
namespace: {{ .Release.Namespace }}
24+
spec:
25+
selector:
26+
matchLabels:
27+
app.kubernetes.io/name: {{ .Release.Name }}
28+
defectdojo.org/component: celery
29+
defectdojo.org/subcomponent: beat
30+
{{ toYaml (omit .Values.celery.beat.podDisruptionBudget "enabled" ) | indent 2 }}
31+
{{- end }}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{{- if .Values.django.autoscaling.enabled -}}
2+
{{- $fullName := include "defectdojo.fullname" . -}}
3+
apiVersion: autoscaling/v2
4+
kind: HorizontalPodAutoscaler
5+
metadata:
6+
{{- if or .Values.extraAnnotations .Values.django.autoscaling.annotations }}
7+
annotations:
8+
{{- range $key, $value := .Values.extraAnnotations }}
9+
{{ $key }}: {{ quote $value }}
10+
{{- end }}
11+
{{- range $key, $value := .Values.django.annotations }}
12+
{{ $key }}: {{ quote $value }}
13+
{{- end }}
14+
{{- end }}
15+
name: {{ $fullName }}-django
16+
namespace: {{ .Release.Namespace }}
17+
labels:
18+
defectdojo.org/component: django
19+
app.kubernetes.io/name: {{ include "defectdojo.name" . }}
20+
app.kubernetes.io/instance: {{ .Release.Name }}
21+
app.kubernetes.io/managed-by: {{ .Release.Service }}
22+
helm.sh/chart: {{ include "defectdojo.chart" . }}
23+
{{- range $key, $value := .Values.extraLabels }}
24+
{{ $key }}: {{ quote $value }}
25+
{{- end }}
26+
spec:
27+
scaleTargetRef:
28+
apiVersion: apps/v1
29+
kind: "Deployment"
30+
name: {{ $fullName }}-django
31+
minReplicas: {{ .Values.django.autoscaling.minReplicas }}
32+
maxReplicas: {{ .Values.django.autoscaling.maxReplicas }}
33+
metrics:
34+
{{- with .Values.django.autoscaling.targetCPUUtilizationPercentage }}
35+
- type: Resource
36+
resource:
37+
name: cpu
38+
target:
39+
averageUtilization: {{ . }}
40+
type: Utilization
41+
{{- end }}
42+
{{- with .Values.django.autoscaling.targetMemoryUtilizationPercentage }}
43+
- type: Resource
44+
resource:
45+
name: memory
46+
target:
47+
averageUtilization: {{ . }}
48+
type: Utilization
49+
{{- end }}
50+
{{- if .Values.django.autoscaling.autoscaleBehavior }}
51+
behavior: {{ toYaml .Values.django.autoscaling.autoscaleBehavior | nindent 4 }}
52+
{{- end }}
53+
{{- end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if .Values.django.podDisruptionBudget.enabled }}
2+
{{- $fullName := include "defectdojo.fullname" . -}}
3+
apiVersion: policy/v1
4+
kind: PodDisruptionBudget
5+
metadata:
6+
{{- if or .Values.extraAnnotations .Values.django.podDisruptionBudget.annotations }}
7+
annotations:
8+
{{- range $key, $value := .Values.extraAnnotations }}
9+
{{ $key }}: {{ quote $value }}
10+
{{- end }}
11+
{{- range $key, $value := .Values.django.annotations }}
12+
{{ $key }}: {{ quote $value }}
13+
{{- end }}
14+
{{- end }}
15+
labels:
16+
defectdojo.org/component: django
17+
app.kubernetes.io/name: {{ include "defectdojo.name" . }}
18+
app.kubernetes.io/instance: {{ .Release.Name }}
19+
app.kubernetes.io/managed-by: {{ .Release.Service }}
20+
helm.sh/chart: {{ include "defectdojo.chart" . }}
21+
{{- range $key, $value := .Values.extraLabels }}
22+
{{ $key }}: {{ quote $value }}
23+
{{- end }}
24+
name: {{ $fullName }}-django
25+
namespace: {{ .Release.Namespace }}
26+
spec:
27+
selector:
28+
matchLabels:
29+
app.kubernetes.io/name: {{ .Release.Name }}
30+
defectdojo.org/component: django
31+
{{ toYaml (omit .Values.django.podDisruptionBudget "enabled" ) | indent 2 }}
32+
{{- end }}

helm/defectdojo/values.schema.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@
5555
"automountServiceAccountToken": {
5656
"type": "boolean"
5757
},
58+
"autoscaling": {
59+
"description": "Autoscaling configuration for Celery beat deployment.",
60+
"type": "object",
61+
"properties": {
62+
"autoscaleBehavior": {
63+
"type": "object"
64+
},
65+
"enabled": {
66+
"type": "boolean"
67+
},
68+
"maxReplicas": {
69+
"type": "integer"
70+
},
71+
"minReplicas": {
72+
"type": "integer"
73+
},
74+
"targetCPUUtilizationPercentage": {
75+
"type": "integer"
76+
},
77+
"targetMemoryUtilizationPercentage": {
78+
"type": "object"
79+
}
80+
}
81+
},
5882
"containerSecurityContext": {
5983
"description": "Container security context for the Celery beat containers.",
6084
"type": "object"
@@ -104,6 +128,21 @@
104128
"description": "Annotations for the Celery beat pods.",
105129
"type": "object"
106130
},
131+
"podDisruptionBudget": {
132+
"description": "Configure pod disruption budgets for Celery beat ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget",
133+
"type": "object",
134+
"properties": {
135+
"enabled": {
136+
"type": "boolean"
137+
},
138+
"minAvailable": {
139+
"type": "string"
140+
},
141+
"unhealthyPodEvictionPolicy": {
142+
"type": "string"
143+
}
144+
}
145+
},
107146
"podSecurityContext": {
108147
"description": "Pod security context for the Celery beat pods.",
109148
"type": "object"
@@ -429,6 +468,30 @@
429468
"automountServiceAccountToken": {
430469
"type": "boolean"
431470
},
471+
"autoscaling": {
472+
"description": "Autoscaling configuration for the Django deployment.",
473+
"type": "object",
474+
"properties": {
475+
"autoscaleBehavior": {
476+
"type": "object"
477+
},
478+
"enabled": {
479+
"type": "boolean"
480+
},
481+
"maxReplicas": {
482+
"type": "integer"
483+
},
484+
"minReplicas": {
485+
"type": "integer"
486+
},
487+
"targetCPUUtilizationPercentage": {
488+
"type": "integer"
489+
},
490+
"targetMemoryUtilizationPercentage": {
491+
"type": "object"
492+
}
493+
}
494+
},
432495
"extraEnv": {
433496
"description": "Additional environment variables injected to all Django containers and initContainers.",
434497
"type": "array"
@@ -594,6 +657,21 @@
594657
"nodeSelector": {
595658
"type": "object"
596659
},
660+
"podDisruptionBudget": {
661+
"description": "Configure pod disruption budgets for django ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget",
662+
"type": "object",
663+
"properties": {
664+
"enabled": {
665+
"type": "boolean"
666+
},
667+
"minAvailable": {
668+
"type": "string"
669+
},
670+
"unhealthyPodEvictionPolicy": {
671+
"type": "string"
672+
}
673+
}
674+
},
597675
"podSecurityContext": {
598676
"description": "Pod security context for the Django pods.",
599677
"type": "object",

helm/defectdojo/values.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ celery:
221221
repository: ""
222222
tag: ""
223223
digest: ""
224+
# -- Autoscaling configuration for Celery beat deployment.
225+
autoscaling:
226+
enabled: false
227+
minReplicas: 2
228+
maxReplicas: 5
229+
targetCPUUtilizationPercentage: 80
230+
targetMemoryUtilizationPercentage: {}
231+
autoscaleBehavior: {}
224232
automountServiceAccountToken: false
225233
# -- Annotations for the Celery beat deployment.
226234
annotations: {}
@@ -251,6 +259,12 @@ celery:
251259
nodeSelector: {}
252260
# -- Annotations for the Celery beat pods.
253261
podAnnotations: {}
262+
# -- Configure pod disruption budgets for Celery beat ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget
263+
podDisruptionBudget:
264+
enabled: false
265+
minAvailable: 50%
266+
# maxUnavailable: ""
267+
unhealthyPodEvictionPolicy: AlwaysAllow
254268
# -- Pod security context for the Celery beat pods.
255269
podSecurityContext: {}
256270
# -- Enable readiness probe for Celery beat container.
@@ -328,6 +342,14 @@ celery:
328342
poolType: solo
329343

330344
django:
345+
# -- Autoscaling configuration for the Django deployment.
346+
autoscaling:
347+
enabled: false
348+
minReplicas: 2
349+
maxReplicas: 5
350+
targetCPUUtilizationPercentage: 80
351+
targetMemoryUtilizationPercentage: {}
352+
autoscaleBehavior: {}
331353
automountServiceAccountToken: false
332354
annotations: {}
333355
service:
@@ -380,6 +402,12 @@ django:
380402
cpu: 2000m
381403
memory: 256Mi
382404
nodeSelector: {}
405+
# -- Configure pod disruption budgets for django ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget
406+
podDisruptionBudget:
407+
enabled: false
408+
minAvailable: 50%
409+
# maxUnavailable: ""
410+
unhealthyPodEvictionPolicy: AlwaysAllow
383411
replicas: 1
384412
strategy: {}
385413
tolerations: []

0 commit comments

Comments
 (0)