Skip to content

Commit 8916e76

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 8916e76

File tree

10 files changed

+418
-0
lines changed

10 files changed

+418
-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 and Django deployments for Horizontal Pod Autoscaler using `.autoscaling` fields under each section. And Pod Disruption Budget using `.podDisruptionBudget` for any of Celery Beat/Worker or Django deployments.
38+
3539
#### Moved values
3640

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

helm/defectdojo/README.md

Lines changed: 6 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` | |
@@ -553,6 +555,7 @@ A Helm chart for Kubernetes to install DefectDojo
553555
| celery.worker.annotations | object | `{}` | Annotations for the Celery worker deployment. |
554556
| celery.worker.appSettings.poolType | string | `"solo"` | Performance improved celery worker config when needing to deal with a lot of findings (e.g deduplication ops) poolType: prefork autoscaleMin: 2 autoscaleMax: 8 concurrency: 8 prefetchMultiplier: 128 |
555557
| celery.worker.automountServiceAccountToken | bool | `false` | |
558+
| celery.worker.autoscaling | object | `{"autoscaleBehavior":{},"enabled":false,"maxReplicas":5,"minReplicas":2,"targetCPUUtilizationPercentage":80,"targetMemoryUtilizationPercentage":{}}` | Autoscaling configuration for Celery worker deployment. |
556559
| celery.worker.containerSecurityContext | object | `{}` | Container security context for the Celery worker containers. |
557560
| celery.worker.extraEnv | list | `[]` | Additional environment variables injected to Celery worker containers. |
558561
| celery.worker.extraInitContainers | list | `[]` | A list of additional initContainers to run before celery worker containers. |
@@ -562,6 +565,7 @@ A Helm chart for Kubernetes to install DefectDojo
562565
| celery.worker.livenessProbe | object | `{}` | Enable liveness probe for Celery worker containers. ``` exec: command: - bash - -c - celery -A dojo inspect ping -t 5 initialDelaySeconds: 30 periodSeconds: 60 timeoutSeconds: 10 ``` |
563566
| celery.worker.nodeSelector | object | `{}` | |
564567
| celery.worker.podAnnotations | object | `{}` | Annotations for the Celery beat pods. |
568+
| celery.worker.podDisruptionBudget | object | `{"enabled":false,"minAvailable":"50%","unhealthyPodEvictionPolicy":"AlwaysAllow"}` | Configure pod disruption budgets for Celery worker ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget |
565569
| celery.worker.podSecurityContext | object | `{}` | Pod security context for the Celery worker pods. |
566570
| celery.worker.readinessProbe | object | `{}` | Enable readiness probe for Celery worker container. |
567571
| celery.worker.replicas | int | `1` | |
@@ -595,6 +599,7 @@ A Helm chart for Kubernetes to install DefectDojo
595599
| django.affinity | object | `{}` | |
596600
| django.annotations | object | `{}` | |
597601
| django.automountServiceAccountToken | bool | `false` | |
602+
| django.autoscaling | object | `{"autoscaleBehavior":{},"enabled":false,"maxReplicas":5,"minReplicas":2,"targetCPUUtilizationPercentage":80,"targetMemoryUtilizationPercentage":{}}` | Autoscaling configuration for the Django deployment. |
598603
| django.extraEnv | list | `[]` | Additional environment variables injected to all Django containers and initContainers. |
599604
| django.extraInitContainers | list | `[]` | A list of additional initContainers to run before the uwsgi and nginx containers. |
600605
| django.extraVolumeMounts | list | `[]` | Array of additional volume mount points common to all containers and initContainers. |
@@ -622,6 +627,7 @@ A Helm chart for Kubernetes to install DefectDojo
622627
| django.nginx.tls.enabled | bool | `false` | |
623628
| django.nginx.tls.generateCertificate | bool | `false` | |
624629
| django.nodeSelector | object | `{}` | |
630+
| 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 |
625631
| django.podSecurityContext | object | `{"fsGroup":1001}` | Pod security context for the Django pods. |
626632
| django.replicas | int | `1` | |
627633
| 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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{- if .Values.celery.worker.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.worker.annotations }}
7+
annotations:
8+
{{- range $key, $value := . }}
9+
{{ $key }}: {{ quote $value }}
10+
{{- end }}
11+
{{- end }}
12+
name: {{ $fullName }}-celery-worker
13+
namespace: {{ .Release.Namespace }}
14+
labels:
15+
defectdojo.org/component: celery
16+
defectdojo.org/subcomponent: worker
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-worker
29+
minReplicas: {{ .Values.celery.worker.autoscaling.minReplicas }}
30+
maxReplicas: {{ .Values.celery.worker.autoscaling.maxReplicas }}
31+
metrics:
32+
{{- with .Values.celery.worker.autoscaling.targetCPUUtilizationPercentage }}
33+
- type: Resource
34+
resource:
35+
name: cpu
36+
target:
37+
averageUtilization: {{ . }}
38+
type: Utilization
39+
{{- end }}
40+
{{- with .Values.celery.worker.autoscaling.targetMemoryUtilizationPercentage }}
41+
- type: Resource
42+
resource:
43+
name: memory
44+
target:
45+
averageUtilization: {{ . }}
46+
type: Utilization
47+
{{- end }}
48+
{{- if .Values.celery.worker.autoscaling.autoscaleBehavior }}
49+
behavior: {{ toYaml .Values.celery.worker.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.worker.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.worker.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: worker
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-worker
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: worker
30+
{{ toYaml (omit .Values.celery.worker.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 }}

0 commit comments

Comments
 (0)