Kubernetes Persistent Volume Claim Indefinitely in Pending State
I quickly realized that PersistentVolumeClaim defaults the storageClassName
field to standard
when not specified. However, when creating a PersistentVolume, storageClassName
does not have a default, so the selector doesn't find a match.
The following worked for me:
kind: PersistentVolumeapiVersion: v1metadata: name: models-1-0-0 labels: name: models-1-0-0spec: capacity: storage: 200Gi storageClassName: standard accessModes: - ReadOnlyMany gcePersistentDisk: pdName: models-1-0-0 fsType: ext4 readOnly: true---kind: PersistentVolumeClaimapiVersion: v1metadata: name: models-1-0-0-claimspec: accessModes: - ReadOnlyMany resources: requests: storage: 200Gi selector: matchLabels: name: models-1-0-0
With dynamic provisioning, you shouldn't have to create PVs and PVCs separately. In Kubernetes 1.6+, there are default provisioners for GKE and some other cloud environments, which should let you just create a PVC and have it automatically provision a PV and an underlying Persistent Disk for you.
For more on dynamic provisioning, see:
https://kubernetes.io/blog/2017/03/dynamic-provisioning-and-storage-classes-kubernetes/
If you're using Microk8s, you have to enable storage before you can start a PersistentVolumeClaim successfully.
Just do:
microk8s.enable storage
You'll need to delete your deployment and start again.
You may also need to manually delete the "pending" PersistentVolumeClaims because I found that uninstalling the Helm chart which created them didn't clear the PVCs out.
You can do this by first finding a list of names:
kubectl get pvc --all-namespaces
then deleting each name with:
kubectl delete pvc name1 name2 etc...
Once storage is enabled, reapplying your deployment should get things going.