Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in resizing PVC: Only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize

I am trying to create pvc which can be resized later on demand.

I am using this code from github for mongodb pvc.

I followed all the steps and pvc is created as below:

PS C:\Users> minikube kubectl -- get pvc
NAME         STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mongo-data   Bound     pvc-4a22efc0-9fd3-42dc-80a7-db86e8f2c189   1Gi        RWO            standard       32m

I edited the file mongodb-pvc.yaml and changed the storage field to 2 GB. storage: 2Gi and then again executed kubectl apply command and got below error:

  PS C:\Users> minikube kubectl -- apply -f mongodb-pvc.yaml
    Error from server (Forbidden): error when applying patch:
    {"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"PersistentVolumeClaim\",\"metadata\":{\"annotations\":{},\"name\":\"mongo-data\",\"namespace\":\"default\"},\"spec\":{\"accessModes\":[\"ReadWriteOnce\"],\"resources\":{\"requests\":{\"storage\":\"2Gi\"}}}}\n"}},"spec":{"resources":{"requests":{"storage":"2Gi"}}}}
    to:
    Resource: "/v1, Resource=persistentvolumeclaims", GroupVersionKind: "/v1, Kind=PersistentVolumeClaim"
    Name: "mongo-data", Namespace: "default"
    for: "mongodb-pvc.yaml": persistentvolumeclaims "mongo-data" is forbidden: only dynamically provisioned pvc can be resized and the storageclass that provisions the PVC must support resize

I tried using the storageclass also, but unable to map it correctly.

Please help, I am a beginner in Kubernetes and especially in PVC.

like image 956
SecureTech Avatar asked Nov 15 '25 03:11

SecureTech


1 Answers

In order to resize a PVC, it is required to have the attribute allowVolumeExpansion set to “true” in your storage class definition. Otherwise, you won't be able to perform the update.

You can follow these steps and add this attribute to its YAML:

  1. In Kubernetes Engine -> Storage -> Storage Classes, select the storage class that you are using for your PVC.

  2. Go to its YAML file and add the instruction. As is explained in the following documentation:

     allowVolumeExpansion: true
    

Once the YAML file is modified, try to perform the resize of the PVC once again

like image 139
Fariya Rahmat Avatar answered Nov 17 '25 20:11

Fariya Rahmat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!