gpt4 book ai didi

kubernetes - 持久卷声明未声明卷

转载 作者:行者123 更新时间:2023-12-02 11:31:43 25 4
gpt4 key购买 nike

我有这个持久的音量声明

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

最佳答案

要了解错误信息,您需要了解如何staticdynamic供应工作。

When none of the static PVs the administrator created matches a user's PersistentVolumeClaim, the cluster may try to dynamically provision a volume especially for the PVC. This provisioning is based on StorageClasses.


After you create the PersistentVolumeClaim, the Kubernetes control plane looks for a PersistentVolume that satisfies the claim's requirements. If the control plane finds a suitable PersistentVolume with the same StorageClass, it binds the claim to the volume.


您的错误说,“您的 PVC 没有找到匹配的 PV,您也没有提到任何 storageClass 名称”。
您的 PV 有 StorageClass: manual ,但您的 PVC 没有任何 storageClass ( StorageClass: "" )。添加 StorageClass: manual到您的 PVC 应该可以解决您的问题。
您必须需要选择以下配置选项之一。
静态配置:
  • 创建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 名称创建 PVC

  • 或者
  • 使用提到的相同 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更多细节。

    关于kubernetes - 持久卷声明未声明卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63552085/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com