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)
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.
Other articles on Devops -
- Setup kubernetes on Ubuntu
- Setup Kubernetes on CentOs
- Setup HA Kubernetes Cluster with Kubespray
- Setup HA Kubernetes with Minikube
- Setup Kubernetes Dashboard for local kubernetes cluster
- Setup Kubernetes Dashboard On GCP(Google Cloud Platform)
- How to use Persistent Volume and Persistent Volume Claims in Kubernetes
- Deploy Spring Boot Microservice on local Kubernetes cluster
- Deploy Spring Boot Microservice on Cloud Platform(GCP)
- Setting up Ingress controller NGINX along with HAproxy inside Kubernetes cluster
- CI/CD Kubernetes | Setting up CI/CD Jenkins pipeline for kubernetes
- kubectl export YAML | Get YAML for deployed kubernetes resources(service, deployment, PV, PVC….)
- How to setup kubernetes jenkins pipeline on AWS?
- Implementing Kubernetes liveness, Readiness and Startup probes with Spring Boot Microservice Application?
- How to fix kubernetes pods getting recreated?
- How to delete all kubernetes PODS?
- How to use Kubernetes secrets?
- Share kubernetes secrets between namespaces?