kubernetespersistent-volumespersistent-volume-claims

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?


Solution

  • 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