Skip to content

Commit 40bbd57

Browse files
authored
Merge pull request #753 from MeVitae/k8s-dabase-update
Add persistent storage to mysql database in K8s and a volume in docker-compose
2 parents 74b9834 + e8f055a commit 40bbd57

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

Docker/alpine-cloud/k8s/Deployment_mysql.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ spec:
1515
app.kubernetes.io/name: mysql
1616
app.kubernetes.io/instance: mysql
1717
---
18+
apiVersion: v1
19+
kind: PersistentVolumeClaim
20+
metadata:
21+
name: mysql-pv-claim
22+
labels:
23+
app.kubernetes.io/name: mysql
24+
app.kubernetes.io/instance: mysql
25+
app.kubernetes.io/version: "2.2.2"
26+
spec:
27+
accessModes:
28+
- ReadWriteOnce
29+
resources:
30+
requests:
31+
storage: 8Gi
32+
---
1833
apiVersion: apps/v1
1934
kind: Deployment
2035
metadata:
@@ -35,12 +50,19 @@ spec:
3550
app.kubernetes.io/name: mysql
3651
app.kubernetes.io/instance: mysql
3752
spec:
53+
volumes:
54+
- name: mysql-storage
55+
persistentVolumeClaim:
56+
claimName: mysql-pv-claim
3857
containers:
3958
- name: mysql
4059
image: blabla1337/mysql
4160
imagePullPolicy: IfNotPresent
4261
ports:
4362
- containerPort: 3306
63+
volumeMounts:
64+
- name: mysql-storage
65+
mountPath: /var/lib/mysql
4466
env:
4567
- name: MYSQL_DEFAULT_USER
4668
valueFrom:
@@ -62,4 +84,4 @@ spec:
6284
configMapKeyRef:
6385
name: mysql
6486
key: MYSQL_DATABASE
65-
---
87+
---

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ services:
2323
MYSQL_DEFAULT_USER: 'root'
2424
ports:
2525
- '3306:3306'
26+
volumes:
27+
- mysql_data:/var/lib/mysql
2628

2729
nginx:
2830
container_name: skf-nginx_container
@@ -70,3 +72,5 @@ services:
7072
#- SKF_LABS_DEPLOY_MODE=subdomain
7173
#- JWT_ENABLED="False"
7274
#- SKF_DOJO_API_KEY=
75+
volumes:
76+
mysql_data: {}

installations/Kubernetes/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ Horizontal auto-scaling for the API server. You might want to change the `minRep
7676

7777
## `Deployment_mysql.yaml`
7878

79-
MySQL service and deployment. Authentication variables are set in `configmaps.yaml` and also used by
80-
`Deployment_backend.yaml`.
79+
MySQL service, persistent volume claim and deployment. Authentication variables are set in
80+
`configmaps.yaml` and also used by `Deployment_backend.yaml`. The persistent volume requests 8GiB by
81+
default.
82+
83+
If you're deploying to a cloud provider, you might want to use their database service instead and
84+
not deploy this. The database URL is set in `configmaps.yaml`.
85+
86+
If this is used, make sure you back up the persistent volume!
8187

8288
## `Deployment_rabbitmq.yaml`
8389

installations/docker/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ First we want to select “Enable Kubernetes” after which we press on “Apply
2121
For Linux users you may want to look at Minikube for deploying locally. Alternatively if you do not want to go through all the hassle of installing a local kubernetes cluster you can also provide the configuration file from the cloud provider of your choosing, or simply choose to clone the lab repository and run them as flask applications with python as described here. After setting up our local cluster it is time to perform a “docker-compose up” command in the root directory of the SKF project.
2222

2323
WARNING, before doing below steps make sure you selected the right context (docker-desktop)
24-
Now we need to edit the docker-compose.yaml file and change the value LABS_KUBE_CONF to the new value:
24+
Now we need to edit the docker-compose.yaml file and change the value `LABS_KUBE_CONF` to the new value:
2525
```
2626
# Below is the variable where we place the base64 string that will be used in the .kube/config file in the cluster
2727
# file for example: cat ~/.kube/config | base64
@@ -45,7 +45,15 @@ If you are done don't forget to kill it again with:
4545
docker-compose down
4646
```
4747

48-
5. Location of SKF images
48+
To clear the database, too:
49+
```
50+
docker-compose down --volumes
51+
```
52+
53+
5. By default, the login will be skipped when using docker compose locally. To change this, update
54+
the value of `SKIP_LOGIN` to `skfprovider` in `docker-compose.yml`.
55+
56+
6. Location of SKF images
4957
We also have a list of old OWASP-SKF Docker images available:
5058

5159
Angular:

0 commit comments

Comments
 (0)