skip to Main Content

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


  1. As the error indicates, it’s not pointing to the correct storageClass. Check if the storageClass standard-rwo exists already with with kubectl get sc (create one if there’s none) and add the storageClassName while claiming the volume. You don’t need to create a PV explicitly, when you create a PVC using storageClass,it will automatically provision a PV object for you.

    Login or Signup to reply.
  2. 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:

    A claim can request a particular class by specifying the name of a StorageClass using the attribute storageClassName. Only PVs of the requested class, ones with the same storageClassName as the PVC, can be bound to the PVC.

    PVCs don’t necessarily have to request a class. A PVC with its storageClassName set equal to "" is always interpreted to be requesting a PV with no class, so it can only be bound to PVs with no class (no annotation or one set equal to ""). A PVC with no storageClassName is not quite the same and is treated differently by the cluster, depending on whether the DefaultStorageClass admission plugin is turned on.

    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:

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: mongo-pv
    spec:
      storageClassName: standard-rwo
      capacity:
        storage: 256Mi
      accessModes:
        - ReadWriteOnce
      hostPath:
        path: /tmp/db
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search