Skip to content

Commit 7e52520

Browse files
zazathomaskiblik
andauthored
Added instructions for using an external postgresql db with defectdoj… (#10859)
* Added instructions for using an external postgresql db with defectdojo on kuberneetes * Fixed linting issues Co-authored-by: kiblik <5609770+kiblik@users.noreply.github.com> * Fixed linting issues Co-authored-by: kiblik <5609770+kiblik@users.noreply.github.com> * Fixed linting issues Co-authored-by: kiblik <5609770+kiblik@users.noreply.github.com> --------- Co-authored-by: kiblik <5609770+kiblik@users.noreply.github.com>
1 parent bd4ec7c commit 7e52520

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

readme-docs/KUBERNETES.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,84 @@ extraEnv:
375375
value: '26379'
376376
```
377377
378+
379+
### How to use an external PostgreSQL DB with Defectdojo
380+
381+
#### Step 1: Create a Namespace for DefectDojo
382+
383+
To begin, create a dedicated namespace for DefectDojo to isolate its resources:
384+
`kubectl create ns defectdojo`
385+
#### Step 2: Create a Secret for PostgreSQL Credentials
386+
387+
Set up a Kubernetes Secret to securely store the PostgreSQL user password and database connection URL, which are essential for establishing a secure connection between DefectDojo and your PostgreSQL instance. Apply the secret using the following command: `kubectl apply -f secret.yaml -n defectdojo`. This secret will be referenced within the `extraEnv` section of the DefectDojo Helm values file.
388+
389+
Sample secret template (replace the placeholders with your PostgreSQL credentials):
390+
```YAML
391+
apiversion: v1
392+
kind: Secret
393+
metadata:
394+
name: defectdojo-postgresql-specific
395+
type: Opaque
396+
stringData: # I chose stringData for better visualization of the credentials for debugging
397+
postgresql-password: <user-password>
398+
db-url: psql://<username>:<password>@<hostname>:<port>/<database-name>
399+
```
400+
401+
#### Step 2.5: Install PostgreSQL (Optional)
402+
403+
If you need to simulate a PostgreSQL database external to DefectDojo, you can install PostgreSQL using the following Helm command:
404+
405+
```bash
406+
helm repo add bitnami https://charts.bitnami.com/bitnami
407+
helm repo update
408+
helm install defectdojo-postgresql bitnami/postgresql -n defectdojo -f postgresql/values.yaml
409+
```
410+
411+
412+
Sample `values.yaml` file for PostgreSQL configuration:
413+
414+
```YAML
415+
auth:
416+
  username: defectdojo
417+
  password: <user-password>
418+
  postgresPassword: <admin-password>
419+
  database: defectdojo
420+
  primary:
421+
    persistence:
422+
    size: 10Gi
423+
```
424+
425+
#### Step 3: Modify DefectDojo helm values
426+
427+
Before installing the DefectDojo Helm chart, it's important to customize the `values.yaml` file. Key areas to modify include specifying the PostgreSQL connection details & the extraEnv block:
428+
429+
```yaml
430+
database: postgresql
431+
postgresql:
432+
  postgresServer: "defectdojo-postgresql" # point to the hostname of your postgresql server
433+
  enabled: false
434+
435+
# Specify the postgresql DB connection url for the external postgresql server
436+
extraEnv:
437+
  - name: DD_DATABASE_URL
438+
    valueFrom:
439+
      secretKeyRef:
440+
        name: defectdojo-postgresql-specific
441+
        key: db-url
442+
```
443+
444+
#### Step 4: Deploy DefectDojo
445+
446+
After modifying the `values.yaml` file as needed, deploy DefectDojo using Helm. This command also generates the required secrets for the DefectDojo admin UI and Redis:
447+
448+
```bash
449+
helm install defectdojo defectdojo -f values.yaml -n defectdojo --set createSecret=true --set createRedisSecret=true
450+
```
451+
452+
453+
**NOTE**: It is important to highlight that this setup can also be utilized for achieving high availability (HA) in PostgreSQL. By placing a load balancer in front of the PostgreSQL cluster, read and write requests can be efficiently routed to the appropriate primary or standby servers as needed.
454+
455+
378456
### kubectl commands
379457

380458
```zsh

0 commit comments

Comments
 (0)