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

annette_dio picture annette_dio · Feb 11, 2020 · Viewed 14.3k times · Source

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

Answer

coderanger picture coderanger · Feb 12, 2020

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