nordvpn

Increase the size of the persistent volume (PV) in Kubernetes

In this series of Kubernetes, I will show you how to increase the size of the Persistent Volume or PV. I am focusing on AWS EKS in this tutorial but you can also try this on other platforms.

Sometimes we need to increase the size of the PV so you can just follow this article to do that.

Read Also: Get Kubernetes events according to date using kubectl

1. Check StorageClass Settings

First of all, you need to make sure the StorageClass has allowVolumeExpansion enabled.

~ kubectl get storageclass gp2 -o yaml
...
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
storageclass.kubernetes.io/is-default-class: "true"
name: gp2
mountOptions:
- debug
parameters:
type: gp2
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Retain
allowVolumeExpansion: true #This setting should be enabled

So now we can go ahead and increase the PVC.

Note: only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize

Read Also: Kubernetes get pods on a Specific Node

2. Increase the size of the persistent volume

Now you can increase the storage size of the PVC. ( You cannot decrease the size of the volume)~ kubectl edit pvc [claim-name] -n namespace
...
spec:
accessModes:
- ReadWriteOnce
dataSource: null
resources:
requests:
storage: 30Gi # increase the value here
storageClassName: gp2

Save the file and check the status of the Persistent Volume (PV) associated with PVC.

3. Delete or Restart the Pod

When you edit the PVC you will receive a message like this.

message: Waiting for user to (re-)start a pod to finish file system resize of volume on the node.

So, let’s restart the pods on which volume is mounted.

kubectl delete pod [pod-name] -n namespace

After a few minutes, the pod will be up and running with the updated size of the volume.

Please let me know if you have any issues using this tutorial.

https://amzn.to/2WMJBSZ

Leave a Reply

Your email address will not be published.


*



The reCAPTCHA verification period has expired. Please reload the page.

48-Hour Flash Sale! Courses from just $10.99