Hi All I use GKE and created a cluster in Google cloud.
Here is my Persistent volume
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongo-pv
spec:
capacity:
storage: 256Mi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/db
Here is the command that created persistent volume
kubectl create -f mongo-pv.yaml
persistentvolumeclaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-pvc
spec:
accessModes:
- ReadWriteOnce
volumeName: mongo-pv
resources:
requests:
storage: 256Mi
applied using
kubectl create -f mongo-pvc.yaml
however the command to get pvc always shows pending. It should be showing up. Not sure what is wrong in the yaml files
kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mongo-pvc Pending mongo-pv 0 standard-rwo
Update
kubectl describe pvc mongo-pvc
Name: mongo-pvc
Namespace: default
StorageClass: standard-rwo
Status: Pending
Volume: mongo-pv
Labels: <none>
Annotations: <none>
Finalizers: [kubernetes.io/pvc-protection]
Capacity: 0
Access Modes:
VolumeMode: Filesystem
Used By: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning VolumeMismatch 23s (x262 over 65m) persistentvolume-controller Cannot bind to requested volume "mongo-pv": storageClassName does not match
2
Answers
As the error indicates, it’s not pointing to the correct
storageClass
. Check if the storageClassstandard-rwo
exists already with withkubectl get sc
(create one if there’s none) and add thestorageClassName
while claiming the volume. You don’t need to create a PV explicitly, when you create a PVC usingstorageClass
,it will automatically provision a PV object for you.Your PV’s storage class name is empty but your PVC’s storage class name is filled automatically as
standard-rwo
because of the DefaultStorageClass admission plugin.These paragraphs are from Kubernetes documentation:
I guess you should either turn off DefaultStorageClass admission plugin and apply your manifests again or give your PV the same storage class name like this: