pvc扩容空间

确认storageclass是否允许扩容

  • 找到deployment对应的sc名称,这里与Prometheus应用为例
# pvc名称
$ kubectl -n kube-mon get deployments prometheus -ojsonpath='{range .spec.template.spec.volumes[*]}{.persistentVolumeClaim.claimName}{end}{"\n"}'
prometheus-data

# sc名称
$ kubectl -n kube-mon get pvc prometheus-data -o jsonpath='{.spec.storageClassName}{"\n"}'
csi-cephfs-sc
  • 查看sc的详情信息
# 使用上面获取的 sc 名称
$ kubectl describe sc csi-cephfs-sc
Name:            csi-cephfs-sc
IsDefaultClass:  No
Annotations:     kubectl.kubernetes.io/last-applied-configuration={"allowVolumeExpansion":true,"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"csi-cephfs-sc"},"mountOptions":["debug"],"parameters":{"clusterID":"b87d2535-406b-442d-8de2-49d86f7dc599","csi.storage.k8s.io/controller-expand-secret-name":"csi-cephfs-secret","csi.storage.k8s.io/controller-expand-secret-namespace":"kube-storage","csi.storage.k8s.io/node-stage-secret-name":"csi-cephfs-secret","csi.storage.k8s.io/node-stage-secret-namespace":"kube-storage","csi.storage.k8s.io/provisioner-secret-name":"csi-cephfs-secret","csi.storage.k8s.io/provisioner-secret-namespace":"kube-storage","fsName":"cephfs"},"provisioner":"cephfs.csi.ceph.com","reclaimPolicy":"Delete"}

Provisioner:           cephfs.csi.ceph.com
Parameters:            clusterID=b87d2535-406b-442d-8de2-49d86f7dc599,csi.storage.k8s.io/controller-expand-secret-name=csi-cephfs-secret,csi.storage.k8s.io/controller-expand-secret-namespace=kube-storage,csi.storage.k8s.io/node-stage-secret-name=csi-cephfs-secret,csi.storage.k8s.io/node-stage-secret-namespace=kube-storage,csi.storage.k8s.io/provisioner-secret-name=csi-cephfs-secret,csi.storage.k8s.io/provisioner-secret-namespace=kube-storage,fsName=cephfs
AllowVolumeExpansion:  True
MountOptions:
  debug
ReclaimPolicy:      Delete
VolumeBindingMode:  Immediate
Events:             <none>

查看是否 AllowVolumeExpansion 是否为 True
如果不存在该参数,则不支持动态扩容pvc容量

查看原来的pvc容量大小

$ kubectl -n kube-mon exec -it prometheus-56c5b49699-m2sft -- df -h /prometheus
Filesystem                Size      Used Available Use% Mounted on
ceph-fuse                10.0G      9.0G    976.0M  90% /prometheus

停止deployment应用

$ kubectl -n kube-mon scale deployment prometheus --replicas=0
deployment.apps/prometheus scaled

$ kubectl -n kube-mon get deployments prometheus 
NAME         READY   UP-TO-DATE   AVAILABLE   AGE
prometheus   0/0     0            0           24h

扩容pvc容量

$ kubectl -n kube-mon patch persistentvolumeclaims prometheus-data -p '{"spec": {"resources": {"requests": {"storage": "20Gi"}}}}'
persistentvolumeclaim/prometheus-data patched

将来原来分区 /prometheus 10G 容量扩容到 10G 的空间

启动deployment应用

$ kubectl -n kube-mon scale deployment prometheus --replicas=1
deployment.apps/prometheus scaled

验证是否扩容成功

$ kubectl -n kube-mon exec -it prometheus-56c5b49699-vvv8n -- df -h /prometheus
Filesystem                Size      Used Available Use% Mounted on
ceph-fuse                20.0G      9.0G     11.0G  45% /prometheus

参考文档

https://kubernetes.io/zh-cn/docs/concepts/storage/storage-classes/#allow-volume-expansion

posted @ 2022-08-02 23:07  jiaxzeng  阅读(116)  评论(0)    收藏  举报