3

I have a PV alpha-pv in the kubernetes cluster and have created a PVC matching the PV specs. The PV uses the Storage Class: slow. However, when I check the existence of Storage Class in Cluster there is no Storage Class existing and still my PVC was Bound to the PV.

How is this Possible when the Storage Class referred in the PV/PVC does not exists in the cluster?

If I don't mention the Storage Class in PVC, I get error message stating Storage Class Set. There is already an existing PV in the cluster which has RWO access modes, 1Gi storage size and with the Storage class named slow. But on checking the Storage Class details, there is no Storage Class resource in cluster.

If I add the Storage Class name slow in my PVC mysql-alpha-pvc, then the PVC binds to the PV. But I'm not clear how this happens when the Storage Class referred in PV/PVC named slow doesn't exist in the cluster.

Storage Class Error in PVC

PVC Bound to PV even when the Storage class named "slow" does not exists in Cluster

moonkotte
  • 3,661
  • 2
  • 10
  • 25
Mayur Kadam
  • 145
  • 1
  • 12
  • Is this a bare-metal deployment or some managed kubernetes service? who is the provisioner of the storage class? This will give idea about default storageClasses. – Vikas Kumar Sep 23 '21 at 07:48
  • Yes, storage class should exist so `PersistentVolumeClaim` can find `storageClass` and create a `PersistentVolume`. Please run this `kubectl get storageclasses` to see if you have any storageclasses. – moonkotte Sep 23 '21 at 09:05
  • No, this is a Virtualized environment. – Mayur Kadam Sep 23 '21 at 09:54
  • Hi @moonkotte , As you can see i have already pasted the output of the command , there is no such storageclass in the Cluster, still the PVC was bound to the Claim. I have ran the command already but there are no storage classes found. – Mayur Kadam Sep 24 '21 at 05:13
  • @MayurKadam Are you following any kind of tutorial? You can remove PV and PVC and storage class. Then add PVC and see what happens (it shouldn't work). Also I can see you have two had two storage classes: `slow` and `slow-storage`. If you don't specify `storageClassName` in PVC, [default one will be used](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reserving-a-persistentvolume) – moonkotte Sep 27 '21 at 08:40
  • Okay, let me check if I understand you correctly. Your question is how it's possible to have PVC and PV bound and no storage class? If so, see [here](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#introduction) - "A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes". So in your case it looks it was provisioned manually so existing of storageclass is not necessary. Is it what you asked about? – moonkotte Sep 28 '21 at 07:45

2 Answers2

3

Short answer

It depends.

Theory

One of the main purpose of using a storageClass is dynamic provisioning. That means that persistent volumes will be automatically provisioned once persistent volume claim requests for the storage: immediately or after pod using this PVC is created. See Volume binding mode.

Also:

A StorageClass provides a way for administrators to describe the "classes" of storage they offer. Different classes might map to quality-of-service levels, or to backup policies, or to arbitrary policies determined by the cluster administrators. Kubernetes itself is unopinionated about what classes represent. This concept is sometimes called "profiles" in other storage systems.

Reference.

How it works

If for instance kubernetes is used in cloud (Google GKE, Azure AKS or AWS EKS), they have already had predefined storageClasses, for example this is from Google GKE:

$ kubectl get storageclasses
NAME                 PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
premium-rwo          pd.csi.storage.gke.io   Delete          WaitForFirstConsumer   true                   27d
standard (default)   kubernetes.io/gce-pd    Delete          Immediate              true                   27d
standard-rwo         pd.csi.storage.gke.io   Delete          WaitForFirstConsumer   true                   27d

So you can create PVC's and refer to storageClass, PV will be created for you.


Another scenario which you faced is you can create PVC and PV with any custom storageClassName only for binding purposes. Usually it's used for testing something locally. This is also called static provisioning.

In this case you can create "fake" storage class which won't exist in kubernetes server.

Please see an example with such type of binding:

It defines the StorageClass name manual for the PersistentVolume, which will be used to bind PersistentVolumeClaim requests to this PersistentVolume.

Useful links:

moonkotte
  • 3,661
  • 2
  • 10
  • 25
0

Hello I already faced the same challenge but solved, Please Make sure :

  1. Your PVC configuration ( RW mode, Size, Name) is matching what is in the PV configuration

  2. Claim name in your Deployment is equal to your PVC

  3. Scale your deployment to (0) then to (1) you will find that it is working smoothly

  4. if you are facing any challenges you could run ( kubectl get events ) to know what is the blocker.