具有pvc的local类型的StorageClass但在kubernetes中给出错误

时间:2018-03-27 02:00:56

标签: kubernetes kubernetes-helm

我想使用路径上安装在我的节点上的本地卷:/ mnts / drive。 所以我创建了一个存储类(如本地存储类的文档中所示), 并创建了一个PVC和一个使用该卷的简单pod。

所以这些是使用的配置:

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

当我尝试创建这个yaml文件时给我一个错误,不知道我错过了什么:

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

1 个答案:

答案 0 :(得分:1)

如果您想使用/mnts/drive路径上节点上安装的本地卷,则只需在您的广告连播中使用hostPath卷:

  

hostPath卷从主机节点安装文件或目录   文件系统进入你的pod。

最终pod.yaml是:

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