持久卷声明未声明卷

Cyb*_*igy 6 gitlab kubernetes prometheus persistent-volume-claims

我有这个持久的音量声明

$ 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
Run Code Online (Sandbox Code Playgroud)

我已经创建了这个持久卷

$ 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>
Run Code Online (Sandbox Code Playgroud)

为什么声明没有声明数量?除了名字,还有什么需要匹配的吗?是否有我应该查看的日志?现在我只看到“没有可用于此声明的持久卷,也没有设置存储类”

Kam*_*san 7

要了解错误消息,您需要了解静态动态配置的工作原理。

当管理员创建的静态 PV 均不匹配用户的 PersistentVolumeClaim 时,集群可能会尝试动态配置卷,特别是为 PVC。此供应基于 StorageClasses。

创建 PersistentVolumeClaim 后,Kubernetes 控制平面会查找满足声明要求的 PersistentVolume。如果控制平面找到具有相同 StorageClass 的合适 PersistentVolume,它会将声明绑定到卷。

您的错误说,“您的 PVC 没有找到匹配的 PV,您也没有提到任何 storageClass 名称”。

您的 PV 有StorageClass: manual,但您的 PVC 没有任何 storageClass ( StorageClass: "")。添加StorageClass: manual到您的 PVC 应该可以解决您的问题。

您必须需要选择以下配置选项之一。

静态配置:

  • 创建光伏
  • 使用标签选择器创建 PVC,以便它可以找到提到标签的 PV。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  selector: # <----- here
    matchLabels:
      release: "stable"
... ...
Run Code Online (Sandbox Code Playgroud)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
  label: # <---- here
    release: "stable"
Run Code Online (Sandbox Code Playgroud)

动态配置:

  • 创建存储类使用提到的供应商
  • 使用提到的 storageClass 名称创建 PVC

或者

  • 使用提到的相同 storageClass 名称创建 PV 和 PVC。
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: slow
provisioner: some-provisioner 
... ... ...
Run Code Online (Sandbox Code Playgroud)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  storageClassName: slow # <---- here
... ... ...
Run Code Online (Sandbox Code Playgroud)

这是一个简短的描述,请访问官方文档了解更多详细信息。