I am running minikube on my mac using VB. I was able to start a database on minikube using declarative approach. But when I delete the deployment then data is lost. Now my questions are -
Here is my yaml file -
apiVersion: v1
kind: Service
metadata:
name: track-mysql
labels:
app: track
spec:
ports:
- port: 3306
selector:
app: track
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
labels:
type: local
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/pv001
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
labels:
app: track
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: track-mysql
labels:
app: track
spec:
selector:
matchLabels:
app: track
strategy:
type: Recreate
template:
metadata:
labels:
app: track
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql
key: password
- name: MYSQL_DATABASE
value: track
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pvc
I have checked, on my mac, the data is not on /data/pv001
In your case when you delete the deployment kubernetes will delete all generated resources and all volumes as well.
You can mount local folder and this way you will save your data to a local storage.
Because your persistent volumes are going to be deleted when you delete the deployment then in case you mount the local folder although volumes will be removed your data will be stored on local disk.