kubernetes volume claim pending with specific volume name

5/8/2020

I'm trying to create a PersistentVolumeClaim giv it a specific volumeName to use.

I use this code:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: zipkin  
  name: pvc-ciro
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: nfs-provisioner
  resources:
    requests:
      storage: 0.1Gi
  volumeName: "demo"      

If I remove volumeName the PVC is correctly bound otherways remain in pending status.

Why?

-- ciro
kubernetes
persistent-volume-claims

1 Answer

5/8/2020

The volumeName is a name of the PersistentVolume you want to use.

On GKE PVC can automatically create a PV that will bound to, or you can specify the name of it using volumeName.

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-ciro
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: standard
  resources:
    requests:
      storage: 0.1Gi
  volumeName: demo

pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: demo
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: standard
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /tmp
    server: 172.17.0.2

And the output will be:

$ kubectl get pv
NAME   CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM              STORAGECLASS   REASON   AGE
demo   5Gi        RWO            Recycle          Bound    default/pvc-ciro   standard                13s
$ kubectl get pvc
NAME       STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc-ciro   Bound    demo     5Gi        RWO            standard       8s

You can read more details in Kubernetes documentation regarding Persistent Volumes.

-- Crou
Source: StackOverflow