Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: PersistentVolumeClaim error, Forbidden: is immutable after creation except resources.requests for bound claims

I have created a StorageClass and PersistentVolume but when I try to create a PersistentVolumeClaim I get the following error, "The PersistentVolumeClaim "esp-pv" is invalid: spec: Forbidden: is immutable after creation except resources.requests for bound claims". I have tried to delete the StorageClass PersistentVolume, and PersistentVolumeClaim, as other posts have suggested, and then recreate the sc, pv and pvc but I get the same error.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
   name: manual
provisioner: kubernetes.io/no-provisioner
#volumeBindingMode: WaitForFirstConsumer
volumeBindingMode: Immediate
allowVolumeExpansion: true
apiVersion: v1
kind: PersistentVolume
metadata:
   name: esp-pv-volume   # name of the pv 
   namespace: espkube    # namespace where the p vis applied
   labels:
     type: local
spec:
   storageClassName: manual
   accessModes:
     - ReadWriteMany  # esp, studio and streamviewer can all write to this space
   hostPath:
     path: "/mnt/data/"
   capacity:
     storage: 10Gi  # volume size requested
apiVersion: v1
kind: PersistentVolumeClaim 
metadata:
   name: esp-pv
   namespace: espkube
spec:
   storageClassName: manual
   accessModes:
     - ReadWriteMany # esp, studio and streamviewer can all write to this space
   resources:
     requests:
       storage: 10Gi  # volume size requested
like image 850
annette_dio Avatar asked Feb 11 '20 18:02

annette_dio


2 Answers

You need to comment below in PVC or PV before deleting them, else they would remain in terminating state.

finalizers:
  - kubernetes.io/pv-protection

to

  #finalizers:
  #- kubernetes.io/pv-protection

in order to delete pvc or pv

like image 74
Mr Kashyap Avatar answered Sep 19 '22 12:09

Mr Kashyap


Solved in comments, deleting a namespaced object (which is most of them) requires specifying the namespace.

like image 21
coderanger Avatar answered Sep 18 '22 12:09

coderanger