How to create hostpath PV for db.sqlite3 database in minikube

18 Views Asked by At

I'm building a project(frontend+backend+DB), containerize it, & deploy it on minikube(single node cluster). Due to absence of PV, I lost the data after pod update. Trying to figure out how I can create a PV for hostpath & keep that database on that storage for data persistance.

File structure

I tried out to link deployment.yml with pvc.yml & pvc.yml with pv.yml. While executing pv.yml file giving node affinity error & host path error. can't find how to resolve the error.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mlh-pv
spec:
  capacity:
    storage: 500Mi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /home/parth/storage-mlh
    type: DirectoryOrCreate
  • pvc.yml
 apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mlh-pvc
spec:
  volumeName: mlh-pv
  storageClassName: manual
  resources:
    requests:
      storage: 500Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  • deployment.yml (spec section)
spec:
  selector:
    matchLabels:
      app: mlh-with-hostpath
  template:
    metadata:
      labels:
        app: mlh-with-hostpath
    spec:
      containers:
      - name: mlh-with-hostpath
        image: parth721/django-mlh:4.2
        volumeMounts:
        - name: www-hostpath-storage
          mountPath: /app/db.sqlite3
        resources:
          limits:
            memory: "300Mi"
            cpu: "500m"
        ports:
        - containerPort: 8000
      volumes:
      - name: www-hostpath-storage
        hostPath:
          path: /home/parth/storage-mlh
          type: DirectoryOrCreate
0

There are 0 best solutions below