5

是否需要在节点中手动创建目录还是由 pv 自动创建?

这是我的 pv & pvc 文件,我看到了这个错误

没有可用于此声明的持久卷,也没有设置存储类

如何解决这个问题?

kind: PersistentVolume
apiVersion: v1
metadata:
name: zk1-pv
labels:
  type: local
spec:
storageClassName: manual
capacity:
  storage: 10Mi
accessModes:
  - ReadWriteOnce
hostPath:
  path: "/mr/zk"

cat zk1-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: zk1-pvc
spec:
accessModes:
  - ReadWriteOnce
resources:
  requests:
    storage: 10Mi


kubectl describe pvc zk1-pvc
Name:          zk1-pvc
Namespace:     instavote
StorageClass:
Status:        Pending
Volume:
Labels:        <none>
Annotations:   kubectl.kubernetes.io/last-applied-configuration:
               {"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"name":"zk1-pvc","namespace":"instavote"},"spec":{"accessMo...
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
Events:
Type       Reason         Age                  From                         Message
----       ------         ----                 ----                         -------
Normal     FailedBinding  12s (x14 over 3m7s)  *persistentvolume-controller  no persistent volumes available for this claim and no storage class is set*
Mounted By:  zk1-745b7cbf46-lg7v9
4

2 回答 2

9

回到你的主要问题

是否需要在节点中手动创建目录还是由 pv 自动创建?

首先,输出中的错误与您的问题无关。作为您问题的答案 - 是的。它是由 PV 自动装箱的。

为了做到这一点,首先你必须像下面StorageClassno-provisioner例子一样创建

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: manual
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

然后你必须PersistentVolume通过定义这个storageClassNamehostPath参数来创建,如下所示:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: zk1-pv
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  hostPath:
    path: /mr/zk

然后您必须创建 PVC 和 Pod/Deployment,如下面的示例:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

---
apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
    - name: containerName
      image: gcr.io/google-containers/nginx:1.7.9
      volumeMounts:
      - mountPath: "/var/www/html"
        name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: myclaim

注意:
不要忘记storageClassName: manual在 PVC 和 PV 清单上放置参数。否则他们将无法相互绑定。

希望它清除

于 2019-04-25T12:16:01.813 回答
6

您忘记在 中storageClassName: manual指定PersistentVolumeClaim

于 2019-04-21T11:07:10.203 回答