Mount a local directory to kubernetes pod

3/17/2021

I need to mount a local directory from my C: drive to my local kubernetes pod. Every time I try it tells me the path is incorrect. What is the solution for this?

apiVersion: v1
kind: PersistentVolume
metadata:
  name: dads-files-pv
spec:
  capacity:
    storage: 10Mi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: hostpath
  local:
    path: /dads-files/test
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - docker-desktop # must be the name of your node (kubectl get nodes)
-- Joshua Hopkins
kubernetes
kubernetes-pod

2 Answers

3/17/2021

if you are using the minikube locally you have to map directloy

minikube mount <source directory>:<target directory>

and

minikube mount $HOME:/host

read more at : https://minikube.sigs.k8s.io/docs/handbook/mount/

https://stackoverflow.com/a/48535001/5525824

-- Harsh Manvar
Source: StackOverflow

3/17/2021

I think the definition of your PersistentVolume is not correct.

You should use storageClass manual to use a local folder as PersistentVolume. An example can be found here

apiVersion: v1
kind: PersistentVolume
metadata:
  name: dads-files-pv
spec:
  capacity:
    storage: 10Mi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: manual
  hostPath:
    path: /dads-files/test
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - docker-desktop # must be the name of your node (kubectl get nodes)
-- Jehof
Source: StackOverflow