Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Persistent Volume Claim Indefinitely in Pending State

I created a PersistentVolume sourced from a Google Compute Engine persistent disk that I already formatted and provision with data. Kubernetes says the PersistentVolume is available.

kind: PersistentVolume apiVersion: v1 metadata:   name: models-1-0-0   labels:     name: models-1-0-0 spec:   capacity:     storage: 200Gi   accessModes:     - ReadOnlyMany   gcePersistentDisk:     pdName: models-1-0-0     fsType: ext4     readOnly: true 

I then created a PersistentVolumeClaim so that I could attach this volume to multiple pods across multiple nodes. However, kubernetes indefinitely says it is in a pending state.

kind: PersistentVolumeClaim apiVersion: v1 metadata:   name: models-1-0-0-claim spec:   accessModes:     - ReadOnlyMany   resources:     requests:       storage: 200Gi   selector:     matchLabels:       name: models-1-0-0 

Any insights? I feel there may be something wrong with the selector...

Is it even possible to preconfigure a persistent disk with data and have pods across multiple nodes all be able to read from it?

like image 509
Akash Krishnan Avatar asked Jul 03 '17 17:07

Akash Krishnan


People also ask

Why is PVC pending in state?

Normally the PVCs get created and bound to the cluster quickly, however, in some cases the PVCs fail to bind to the cluster, which results in them getting stuck in the Pending state, this prevents the Platform UI deployment from completing.


1 Answers

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: PersistentVolume apiVersion: v1 metadata:   name: models-1-0-0   labels:     name: models-1-0-0 spec:   capacity:     storage: 200Gi   storageClassName: standard   accessModes:     - ReadOnlyMany   gcePersistentDisk:     pdName: models-1-0-0     fsType: ext4     readOnly: true --- kind: PersistentVolumeClaim apiVersion: v1 metadata:   name: models-1-0-0-claim spec:   accessModes:     - ReadOnlyMany   resources:     requests:       storage: 200Gi   selector:     matchLabels:       name: models-1-0-0 
like image 167
Akash Krishnan Avatar answered Sep 17 '22 14:09

Akash Krishnan