Fixing – Cannot bind to requested volume: storageClasseName does not match

I faced this issue when I started working with kuberenetes Persistent Volume and Kuberenetes Persistent Claim

This issue has occurred because its expecting storageClass to be present inside your kubernetes. Most probably you might have missed creating storageClass or you might have used the wrong storageClass name in your Persistent Volume Claim Configuration

You might have seen Warning ProvisioningFailed persistentvolume-controller storageclass.storage.k8s.io not found

Here is the full stacktrace of the error -

(Below the screenshot you will find the complete log trace)

persistentvolume-controller storageclass.storage.k8s.io not found

 1vagrant@kmaster:~/jhooq-demo-pv$ kubectl describe pvc jhooq-pvc-example
 2Name:          jhooq-pvc-example
 3Namespace:     default
 4StorageClass:  jhooq-storage-class
 5Status:        Pending
 6Volume:        
 7Labels:        <none>
 8Annotations:   Finalizers:  [kubernetes.io/pvc-protection]
 9Capacity:      
10Access Modes:  
11VolumeMode:    Filesystem
12Mounted By:    <none>
13Events:
14  Type     Reason              Age                    From                         Message
15  ----     ------              ----                   ----                         -------
16  Warning  ProvisioningFailed  20h (x62 over 20h)     persistentvolume-controller  storageclass.storage.k8s.io "jhooq-storage-class" not found
17  Warning  ProvisioningFailed  3m8s (x26 over 9m23s)  persistentvolume-controller  storageclass.storage.k8s.io "jhooq-storage-class" not found


How to fix?

Lets first look at my persistent volume claim configuration where I faced this issue -

(I saved the following configuration by the name jhooq-pvc-example.yml)

 1apiVersion: v1
 2kind: PersistentVolumeClaim
 3metadata:
 4  name: jhooq-pvc-example
 5spec:
 6  storageClassName: jhooq-storage-class
 7  volumeMode: Filesystem
 8  accessModes:
 9    - ReadWriteOnce
10  resources:
11    requests:
12      storage: 1Gi

Here in the above configuration you can notice the configuration storageClassName: jhooq-storage-class

So it is expecting a Storage Class with the name jhooq-storage-class to be present inside your kubernetes cluster.



Solution 1 - Create Storage class before applying Persistent Volume Claim

The first approach which I could recommend to fix this issue is to create Storage class before you apply Persistent Volume Claim.

Here is the example configuration for the storage class which you can create -

1apiVersion: storage.k8s.io/v1
2kind: StorageClass
3metadata:
4  name: "jhooq-storage-class"
5provisioner: "kubernetes.io/no-provisioner"
6volumeBindingMode: "WaitForFirstConsumer"

Save the above configuration. In my case I saved the above configuration with the name jhooq-storage-class.yml

Next step would be to apply the configuration

1$ kubectl apply -f jhooq-storage-class.yml

Now your storage class is created.

Let's go back and apply your Persistent Volume Claim Configuration.

1$ kubectl apply -f jhooq-pvc-example.yml

After that your Warning ProvisioningFailed persistentvolume-controller storageclass.storage.k8s.io not found should be gone.



Solution 2 - Use local-storage as your storageClassName

The second solution which I would recommend would be to use local-storage as your preferred storageClassName.

In this approach, you do not need to create storage class but instead, you can use default local-storage provided by Kubernetes.

Here the configuration for Persistent Volume Claim (jhooq-pvc-example.yml)-

 1apiVersion: v1
 2kind: PersistentVolumeClaim
 3metadata:
 4  name: jhooq-pvc-example
 5spec:
 6  volumeName: jhooq-demo-pv
 7  storageClassName: local-storage
 8  volumeMode: Filesystem
 9  accessModes:
10    - ReadWriteOnce
11  resources:
12    requests:
13      storage: 1Gi

Apply the above configuration -

1$ kubectl apply -f jhooq-pvc-example.yml

And it should fix your warning.




Learn more On Kubernetes -

  1. Setup kubernetes on Ubuntu
  2. Setup Kubernetes on CentOs
  3. Setup HA Kubernetes Cluster with Kubespray
  4. Setup HA Kubernetes with Minikube
  5. Setup Kubernetes Dashboard for local kubernetes cluster
  6. Setup Kubernetes Dashboard On GCP(Google Cloud Platform)
  7. How to use Persistent Volume and Persistent Volume Claims in Kubernetes
  8. Deploy Spring Boot Microservice on local Kubernetes cluster
  9. Deploy Spring Boot Microservice on Cloud Platform(GCP)
  10. Setting up Ingress controller NGINX along with HAproxy inside Kubernetes cluster
  11. CI/CD Kubernetes | Setting up CI/CD Jenkins pipeline for kubernetes
  12. kubectl export YAML | Get YAML for deployed kubernetes resources(service, deployment, PV, PVC....)
  13. How to setup kubernetes jenkins pipeline on AWS?
  14. Implementing Kubernetes liveness, Readiness and Startup probes with Spring Boot Microservice Application?
  15. How to fix kubernetes pods getting recreated?
  16. How to delete all kubernetes PODS?
  17. How to use Kubernetes secrets?
  18. Share kubernetes secrets between namespaces?
  19. How to Delete PV(Persistent Volume) and PVC(Persistent Volume Claim) stuck in terminating state?
  20. Delete Kubernetes POD stuck in terminating state?

Posts in this Series