I want to resize Kubernetes Persistent Volume. So I tried by editing
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pvc
labels:
app: postgres
spec:
storageClassName: aws-gp2
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
But I got error following error
error: persistentvolumeclaims "postgres-pvc" could not be patched: persistentvolumeclaims "postgres-pvc" is forbidden: only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize
Then I went to AWS console and resized the PVC to 50GB. Now I see volume size to 50GB
root@postgres-8654848bb4-6897j:/# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 100G 0 disk
├─nvme0n1p1 259:1 0 100G 0 part /etc/hosts
└─nvme0n1p128 259:2 0 1M 0 part
nvme1n1 259:3 0 5G 0 disk
nvme2n1 259:4 0 5G 0 disk
nvme3n1 259:5 0 5G 0 disk
nvme4n1 259:6 0 1G 0 disk
nvme5n1 259:7 0 5G 0 disk
nvme6n1 259:8 0 50G 0 disk /var/lib/postgresql/data
nvme7n1 259:9 0 1G 0 disk
nvme8n1 259:10 0 1G 0 disk
nvme9n1 259:11 0 200G 0 disk
But its not reflecting in df -h
root@postgres-8654848bb4-6897j:/# df -h
Filesystem Size Used Avail Use% Mounted on
overlay 100G 30G 71G 30% /
tmpfs 64M 0 64M 0% /dev
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/nvme0n1p1 100G 30G 71G 30% /etc/hosts
shm 64M 236K 64M 1% /dev/shm
/dev/nvme6n1 9.7G 8.8G 930M 91% /var/lib/postgresql/data
tmpfs 7.0G 12K 7.0G 1% /run/secrets/kubernetes.io/serviceaccount
tmpfs 3.9G 0 3.9G 0% /proc/acpi
tmpfs 3.9G 0 3.9G 0% /sys/firmware
Then I tried resize2fs
command but got following error
root@postgres-8654848bb4-6897j:/# resize2fs /dev/nvme6n1
resize2fs 1.46.2 (28-Feb-2021)
open: No such file or directory while opening /dev/nvme6n1
root@postgres-8654848bb4-6897j:/# resize2fs /var/lib/postgresql/data
resize2fs 1.46.2 (28-Feb-2021)
open: Is a directory while opening /var/lib/postgresql/data
Any help with this here ?
Easiest way you can use the allowVolumeExpansion in StorageClass , i did for Elasticsearch Database
Checkout my article on that : https://medium.com/@harsh.manvar111/resizing-pvc-disk-in-gke-c5b882c90f7b
strogeclasss
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
…
provisioner: kubernetes.io/gce-pd
allowVolumeExpansion: true
Update PVC after this with the desired size you are looking forward to keep and restart the POD.