kubernetesnfspersistent-volumes

Kubernetes persistent volume claim not binding to NFS persistent volume


I'm trying to set up an NFS based persistent volume for a Kubernetes cluster, I have the mount points created and the shares mounted to the clients which are configured to mount at boot: example of share mounted on one of the clients

i have created my volume yaml as follows

apiVersion: v1
kind: PersistentVolume
metadata:
  name: cc-pv-volume
  labels:
    type: local
    author: Administrator
spec:
  storageClassName: manual
  claimRef:
    name: pv-claim
  capacity:
    storage: 2Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
 # persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /nfs/general
    server: 172.16.0.4
    readOnly: false

and my PersistentVolumeClaim yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

When I run the command sudo kubectl apply -f pv-claim.yaml the terminal returns persistentvolumeclaim/pv-claim created yet when i run sudo kubectl get pv cc-pv-volume the status of the volume remains as "Available" rather than showing "bound"

Any ideas as to what I'm doing wrong, thanks, Archvirus

Edit: I noticed that in the PV the AccessMode was: ReadWriteMany but in the PVC the AccessMode was: ReadWriteOnce

I edited the PVC to change the AccessMode to ReadWriteMany as I have 2 nodes (Ubuntu1 and Ubuntu2) yet when I applied this change the terminal returned

The PersistentVolumeClaim "pv-claim" is invalid: spec: Forbidden: spec is immutable after creation except resources.requests and volumeAttributesClassName for bound claims
  core.PersistentVolumeClaimSpec{
-       AccessModes: []core.PersistentVolumeAccessMode{"ReadWriteOnce"},
+       AccessModes: []core.PersistentVolumeAccessMode{"ReadWriteMany"},
        Selector:    nil,
        Resources:   {Requests: {s"storage": {i: {...}, s: "2Gi", Format: "BinarySI"}}},
        ... // 6 identical fields
  }

I tried creating a new yaml file called pv-claim-test which was the same as "pv-claim" but with AccessMode changed to ReadWriteMany, deleted "pv-claim.yaml" and tried to apply the new PVC but the terminal spits out the same error as before.

I believe the issue is that since the PV and PVC had a different StorageClass, the PV wasn't satisfying the requirements of the claim hence it not binding but I don' know why I am unable to apply a new PVC and that when I use the command sudo kubectl apply -f pv-claim-test.yaml the error still references pv-claim.yaml even though pv-claim.yaml no longer exists and I'm not trying to apply that yaml.

result of running "sudo kubectl describe persistentvolume cc-pv-volume" shows that there is no claim, yet it doesn't let me change which PVC is being applied

Name:            cc-pv-volume
Labels:          author=Administrator
                 type=local
Annotations:     <none>
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    manual
Status:          Available
Claim:
Reclaim Policy:  Retain
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        2Gi
Node Affinity:   <none>
Message:
Source:
    Type:      NFS (an NFS mount that lasts the lifetime of a pod)
    Server:    172.16.0.4
    Path:      /nfs/general
    ReadOnly:  false
Events:        <none>

Solution

  • Try recreating the PersistentVolumeClaim object with an explicit reference to the existing PersistentVolume

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pv-claim
    spec:
      volumeName: cc-pv-volume # <--- ADD THIS
      storageClassName: manual
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi