我有这个持续的数量主张

$ kubectl get pvc -ngitlab-managed-apps
NAME                           STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
prometheus-prometheus-server   Pending                                                     0s


$ kubectl describe pvc prometheus-prometheus-server -ngitlab-managed-apps
Name:          prometheus-prometheus-server
Namespace:     gitlab-managed-apps
StorageClass:
Status:        Pending
Volume:
Labels:        app=prometheus
               chart=prometheus-9.5.2
               component=server
               heritage=Tiller
               release=prometheus
Annotations:   <none>
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode:    Filesystem
Mounted By:    prometheus-prometheus-server-78bdf8f5b7-pkvcr
Events:
  Type    Reason         Age                From                         Message
  ----    ------         ----               ----                         -------
  Normal  FailedBinding  14s (x5 over 60s)  persistentvolume-controller  no persistent volumes available for this claim and no storage class is set
我创建了这个持久卷
$ kubectl get pv
NAME                           CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS     CLAIM                                              STORAGECLASS   REASON   AGE
prometheus-prometheus-server   8Gi        RWO            Retain           Released   gitlab-managed-apps/prometheus-prometheus-server   manual                  17m

$ kubectl describe pv prometheus-prometheus-server
Name:            prometheus-prometheus-server
Labels:          type=local
Annotations:     kubectl.kubernetes.io/last-applied-configuration:
                   {"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"labels":{"type":"local"},"name":"prometheus-prometheus-server"}...
                 pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    manual
Status:          Released
Claim:           gitlab-managed-apps/prometheus-prometheus-server
Reclaim Policy:  Retain
Access Modes:    RWO
VolumeMode:      Filesystem
Capacity:        8Gi
Node Affinity:   <none>
Message:
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /var/prometheus-server
    HostPathType:
Events:            <none>
为什么 claim 不要求数量?除了名称,还有其他需要匹配的内容吗?我应该查看任何日志吗?目前,我仅看到“此声明没有可用的永久卷,并且未设置任何存储类”

最佳答案

要了解错误消息,您需要了解staticdynamic供应的工作方式。


您的错误是:“您的PVC找不到匹配的PV,并且您也没有提及任何storageClass名称”。
您的PV带有StorageClass: manual,但是您的PVC没有任何storageClass(StorageClass: "")。在PVC中添加StorageClass: manual应该可以解决您的问题。
您必须选择以下配置选项之一。
静态配置:

  • 创建PV
  • 使用标签选择器创建PVC,以便它可以找到带有标签的PV。

  • apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: myclaim
    spec:
      selector: # <----- here
        matchLabels:
          release: "stable"
    ... ...
    
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: myclaim
      label: # <---- here
        release: "stable"
    
    动态配置:
  • 使用预配者提到的
  • 创建storageClass
  • 用提到的storageClass名称创建PVCt

  • 要么
  • 使用提到的相同的storageClass名称创建PV和PVC。

  • apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: slow
    provisioner: some-provisioner
    ... ... ...
    
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: myclaim
    spec:
      storageClassName: slow # <---- here
    ... ... ...
    
    这是简短描述,请访问official doc了解更多详细信息。

    08-28 03:32