'Kubernetes: Store files in local hard disk using persistent volumes with Minikube

I want to mount a folder that is located on my local hard disk (ex. /home/logon/volumes/algovens/ids/app_data/) on a pod:

{{/home/logon/volumes/algovens/ids/app_data/}} SHOULD BE MOUNTED ON {{/app/app_data/}} ON A POD

I create a persistent volume and a persistent volume claim, then import the pvc on my pod .yaml file. I apply all three yaml files for pv, pvc, pod into kubernetes cluster.

When getting access to the container using interactive bash, I see there's a folder that I've configured to mount from my local hard disk (/app/app_data/ ON POD), but it's still empty.

However, I have some files and folders on my local folder on my local hard disk (/home/logon/volumes/algovens/ids/app_data/)

My configuration files:

identityserver-pv.yaml:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: identityserver-pv
  labels:
    name: identityserver-pv
spec:
  storageClassName: local-storage
  capacity:
    storage: 1Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  local:
    path: /home/logon/volumes/algovens/ids/app_data/
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - minikube

identityserver-pvc.yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: identityserver-pvc
spec:
  storageClassName: local-storage
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

identityserver-deployment.yaml

# Deployment for identityserver

apiVersion: apps/v1
kind: Deployment
metadata:
  name: identityserver-deployment
  labels:
    app: identityserver-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: identityserver
  template:
    metadata:
      labels:
        app: identityserver # pod label
    spec:
      volumes:
        - name: identityserver-pvc
          persistentVolumeClaim:
            claimName: identityserver-pvc
      containers:
      - name: identityserver-container
        image: localhost:5000/algovens-identityserver:v1.0
        ports:
        - containerPort: 80
        volumeMounts:
        - name: identityserver-pvc
          mountPath: "/app/app_data/"
        env:
        - name: ALGOVENS_CORS_ORIGINS
          valueFrom:
            configMapKeyRef:
              name: identityserver-config
              key: ALGOVENS_CORS_ORIGINS
---
# Service for identityserver

apiVersion: v1
kind: Service
metadata:
  name: identityserver-service
spec:
  type: NodePort # External service. default value is ClusterIP
  selector:
    app: identityserver
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30100


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source