2

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)
David Maze
  • 130,717
  • 29
  • 175
  • 215
  • I tried with your exact yaml and i am able to create persistent volume.When do you get the error? – sachin Mar 17 '21 at 13:16
  • A `hostPath` volume will refer to whichever node the pod is running on (and it could change if the pod gets rescheduled on different systems). Kubernetes doesn't know about "your local system" at all. – David Maze Mar 17 '21 at 13:47
  • @Joshua Hopkins Are you using `Minikube` ? – matt_j Mar 17 '21 at 18:43

1 Answers1

0

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
  • 34,674
  • 10
  • 123
  • 155
  • pv created in my local with the exact yaml OP provided. Where can I find the documentation on different storage class names? – sachin Mar 17 '21 at 13:24