我想调整Kubernetes持久卷的大小。所以我试着编辑
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pvc
labels:
app: postgres
spec:
storageClassName: aws-gp2
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
但我得到了错误后的错误
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
然后我去AWS控制台,将PVC大小调整为50GB。现在我看到卷大小为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
但它没有反映在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
然后我尝试resize2fs
命令,但得到以下错误
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
有人能帮忙吗?
1条答案
按热度按时间w6lpcovy1#
使用StorageClass中的allowVolumeExpansion最简单的方法,我为ElasticsearchDatabase做了
看看我的文章:https://medium.com/@harsh.manvar111/resizing-pvc-disk-in-gke-c5b882c90f7b
strogeclasss
在此之后,使用您希望保留的所需大小更新PVC,并重新启动POD**。