Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent volume claim not claiming the volume

I have this persistent volume claim

$ 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

And I have created this persistent volume

$ 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>

Why is the claim not claiming the volume? Besides the name, is there anything else that needs to match? Are there any logs I should look into? For now I only see "no persistent volumes available for this claim and no storage class is set"

like image 848
CyberProdigy Avatar asked Aug 23 '20 21:08

CyberProdigy


1 Answers

To understand the error message, you need to understand how static and dynamic provisioning work.

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.

Your error says,"Your PVC hasn't found a matching PV and you also haven't mentioned any storageClass name".

Your PV has StorageClass: manual, but your PVC doesn't have any storageClass (StorageClass: ""). Adding StorageClass: manual to your PVC should solve your problem.

You must need to choose one of the following provisioning options.

Static provisioning:

  • create PV
  • create PVC with the label selector, so that it can find the PV with labels mentioned.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  selector: # <----- here
    matchLabels:
      release: "stable"
... ...
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
  label: # <---- here
    release: "stable"

Dynamic provisioning:

  • create storageClass with provisioner mentioned
  • create PVC with the storageClass name mentioned

Or

  • create both PV and PVC with the same storageClass name mentioned.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: slow
provisioner: some-provisioner 
... ... ...
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  storageClassName: slow # <---- here
... ... ...

This is a short description, please visit the official doc for more details.

like image 97
Kamol Hasan Avatar answered Nov 10 '22 21:11

Kamol Hasan