> ## Content Index
> Fetch the complete content index at: https://devopscube.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Resize Persistent Volumes in AWS EKS Cluster
- URL: https://devopscube.com/resize-volume-eks-cluster/
- Published: 2024-09-27T15:21:05.000Z
- Updated: 2025-03-13T14:59:19.000Z
- Author: Aswin Vijayan
- Tags: AWS EKS, Kubernetes, #Migrated-1741795015845, #wp, #wp-post, #Import 2025-03-12 15:57, #blog

In this blog, you will learn how to resize the persistent volume in AWS EKS cluster by using a custom storage class with the **`allowVolumeExpansion`** parameter enabled.

## Using Default StorageClass

In every [EKS cluster](https://devopscube.com/create-aws-eks-cluster-eksctl/), there is default Storage class with **`allowVolumeExpansion`** false. Which means you cannot update a persistent volume with the default storage class.

Lets look at the default storage class to understand more.

Run the following command to get the default storageclass name.

```
kubectl get sc
```

The name of my default storage class is given below.

![getting the name of default storage class](https://storage.ghost.io/c/5f/2f/5f2f4d20-2abf-4534-8d40-7aa233aedd43/content/images/2025/03/image-299-1.png)

As you can see in the default storage class, the **`allowVolumeExpansion`** parameter is set as false.

If we try to resize the persistence volume, which uses the default storage class, we will get the below forbidden error.

```
error: persistentvolumeclaims "expandable-pvc" could not be patched: persistentvolumeclaims "expandable-pvc" is forbidden: only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize
You can run `kubectl replace -f /var/folders/w8/zfm6dvnj5ng6cmpv61_nydh00000gn/T/kubectl-edit-57474951.yaml` to try this update again.
```

## Using Custom StorageClass

Let's try to expand a PVC that uses custom storageclass with **`allowVolumeExpansion`** parameter set as true.

### Step 1: Create Custom StorageClass

Now, let's create a custom storage class and create the PVC with the custom storageclass.

Create a YAML file **sc.yaml** and copy the below manifest file content

```
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: expandable-sc
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
allowVolumeExpansion: true
```

You can see in the above manifest file, the **`allowVolumeExpansion`** is set as true.

The EBS volume type is set to **`gp2`**, if you want to use other volume types refer to this [guide](https://docs.aws.amazon.com/ebs/latest/userguide/ebs-volume-types.html?ref=devopscube.com).

Let's create the PVC using the custom storageclass and try to expand the volume size.

Run the following command to create the custom storageclass

```
kubectl apply -f sc.yaml
```

Now, run the below command to check if the storageclass is created

```
kubectl get sc
```

![listing the storage class](https://storage.ghost.io/c/5f/2f/5f2f4d20-2abf-4534-8d40-7aa233aedd43/content/images/2025/03/image-303-1.png)

The custom storageclass `volumeBindingMode` is set as Immediate, which means the PVC will be created and bound with a PV immediately after it's created.

### Step 2: Create PVC

Create a manifest file **pvc.yaml** and copy the below PVC manifest content

```
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: expandable-pvc
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 1Gi
  storageClassName: expandable-sc
```

You can see the storage requested is **`1Gi`**. Run the following command to create a PVC

```
kubectl apply -f pvc.yaml
```

Run the following command to check if the PVC is created.

![checking the status of pvc](https://storage.ghost.io/c/5f/2f/5f2f4d20-2abf-4534-8d40-7aa233aedd43/content/images/2025/03/image-304-1.png)

As you can see, the PVC is in the bound state even without being claimed by a [pod ](https://devopscube.com/kubernetes-pod/)because the custom storageclass we created has the **`volumeBindingMode`** as **`Immediate`**.

### Step 3: Deploy a Pod

Now, create a manifest file **pod.yaml** and copy the below pod deployment manifest content

```
apiVersion: v1
kind: Pod
metadata:
  name: volume-test
spec:
  containers:
  - name: volume-test
    image: nginx
    volumeMounts:
    - name: expandable-storage
      mountPath: /data
  volumes:
  - name: expandable-storage
    persistentVolumeClaim:
      claimName: expandable-pvc
```

Run the following command to deploy the pod

```
kubectl apply -f pod.yaml
```

### Step 4: Expand the Volume Size

Now, run the following command to edit the PVC to expand the volume size.

```
k edit pvc expandable-pvc
```

Then, change the storage request size to **`2Gi`** as shown below

![editing the storage size in pvc yaml](https://storage.ghost.io/c/5f/2f/5f2f4d20-2abf-4534-8d40-7aa233aedd43/content/images/2025/03/image-305-1.png)

Save the changes and exit.

Wait for some time, and the PV and PVC capacity will be increased, as shown below.

![checking the volume size of pvc and pv](https://storage.ghost.io/c/5f/2f/5f2f4d20-2abf-4534-8d40-7aa233aedd43/content/images/2025/03/image-306.png)

Now that the volume has been increased, it's important to check if the filesystem's size inside the pod has also increased.

Run the following command to check whether the filesystem size is increased.

```
kubectl exec -it volume-test -- df -h /data
```

You can see the filesystem size has been increased as well.

![checking if the filesystem size has been changed or not](https://storage.ghost.io/c/5f/2f/5f2f4d20-2abf-4534-8d40-7aa233aedd43/content/images/2025/03/image-307-1.png)

## Conclusion

In this blog, you have seen what happens if we change the volume size in the EKS cluster using the default storage class, which has **`allowVolumeExpansion`** parameter disabled.

Also, you have learned how to expand a volume size using a custom storage class, which has **`allowVolumeExpansion`** parameter enabled.

Also, resizing volume is one of the important topic in [CKA certification](https://devopscube.com/cka-exam-study-guide/).