StorageClass of type local with a pvc but gives an

2019-07-28 21:47发布

i want to use local volume that is mounted on my node on path: /mnts/drive. so i created a storageclass (as shown in documentation for local storageclass), and created a PVC and a simple pod which uses that volume.

so these are the configurations used:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-fast
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysampleclaim
spec:
  storageClassName: local-fast
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: mysamplepod
spec:
  containers:
  - name: frontend
    image: nginx:1.13
    volumeMounts:
    - mountPath: "/var/www/html"
      name: myvolume
  volumes:
  - name: myvolume
    persistentVolumeClaim:
      claimName: mysampleclaim

and when i try to create this yaml file gives me an error, don't know what i am missing:

 Unable to mount volumes for pod "mysamplepod_default(169efc06-3141-11e8-8e58-02d4a61b9de4)": timeout expired list of unattached/unmounted volumes=[myvolume]

1条回答
Summer. ? 凉城
2楼-- · 2019-07-28 22:25

If you want to use local volume that is mounted on the node on /mnts/drive path, you just need to use hostPath volume in your pod:

A hostPath volume mounts a file or directory from the host node’s filesystem into your pod.

The final pod.yaml is:

apiVersion: v1
kind: Pod
metadata:
  name: mysamplepod
spec:
  containers:
  - name: frontend
    image: nginx:1.13
    volumeMounts:
    - mountPath: "/var/www/html"
      name: myvolume
  volumes:
  - name: myvolume
    hostPath:
      # directory location on host
      path: /mnts/drive
查看更多
登录 后发表回答