简体   繁体   中英

Mount a local directory to kubernetes pod

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)

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM