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.
Learn more On Kubernetes -
- 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?
- How to Delete PV(Persistent Volume) and PVC(Persistent Volume Claim) stuck in terminating state?
- Delete Kubernetes POD stuck in terminating state?
Posts in this Series
- Kubernetes Cheat Sheet for day to day DevOps operations?
- Delete Kubernetes POD stuck in terminating state?
- How to Delete PV(Persistent Volume) and PVC(Persistent Volume Claim) stuck in terminating state?
- Share kubernetes secrets between namespaces?
- How to use Kubernetes secrets?
- How to delete all kubernetes PODS?
- kubernetes pods getting recreated?
- Implementing Kubernetes liveness, Readiness and Startup probes with Spring Boot Microservice Application?
- kubectl export yaml OR How to generate YAML for deployed kubernetes resources
- Kubernetes Updates
- CI/CD Kubernetes | Setting up CI/CD Jenkins pipeline for kubernetes
- Kubernetes cluster setup with Jenkins
- How to use Persistent Volume and Persistent Claims | Kubernetes
- How to fix ProvisioningFailed persistentvolume controller no volume plugin matched
- Fixing – Cannot bind to requested volume: storageClasseName does not match
- Fixing – pod has unbound immediate persistentvolumeclaims or cannot bind to requested volume incompatible accessmode
- How to fix kubernetes dashboard forbidden 403 error – message services https kubernetes-dashboard is forbidden User
- How to fix Kubernetes – error execution phase preflight [preflight]
- Deploy Spring Boot microservices on kubernetes?
- How to fix – ansible_memtotal_mb minimal_master_memory_mb
- How to use kubespray – 12 Steps for Installing a Production Ready Kubernetes Cluster
- How to setup kubernetes on CentOS 8 and CentOS 7
- How to fix – How to fix - ERROR Swap running with swap on is not supported. Please disable swap
- 14 Steps to Install kubernetes on Ubuntu 20.04(bento/ubuntu-20.04), 18.04(hashicorp/bionic64)
- Kubernetes Dashboard | Kubernetes Admin GUI | Kubernetes Desktop Client
- Install Kubernetes with Minikube