k8s pvc扩容:pvc创建后扩容

k8s pvc扩容:pvc创建后扩容

img

最开始的10g太小了,现在想扩容pv空间

1、kubernetes 1.11版本中开始支持pvc创建后的扩容

先查看storageclass是否配置了动态扩容,主要看storageclass是否存在allowVolumeExpansion字段

[root@192 ~]# kubectl  get storageclass default -oyaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: default
parameters:
  archiveOnDelete: "false"
provisioner: nfs-client-provisioner-default
reclaimPolicy: Delete
volumeBindingMode: Immediate
[root@192 ~]# 

可以看到并没有allowVolumeExpansion,此时是不支持动态扩容的,可以扩一下测试看看

[root@192 ~]# kubectl edit pvc -n leijun-mysql comom-store-column-03-24 
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: comom-store-column-03-24
  namespace: default
spec:
  accessModes:
  - ReadWriteMany
  dataSource: null
  resources:
    requests:
      storage: 50Gi
  volumeName: pvc-24fc01a0-6d9b-11ea-9107-b8ca3a62236c
status:
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 10Gi
  phase: Bound
"/tmp/kubectl-edit-fkm33.yaml" 38L, 1180C written
error: persistentvolumeclaims "comom-store-column-03-24" could not be patched: persistentvolumeclaims "comom-store-column-03-24" 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 /tmp/kubectl-edit-fkm33.yaml` to try this update again.
[root@192 ~]# 
kubectl edit pvc -n leijun-mysql comom-store-column-03-24
修改storage 字段再保存,报错了,表示不支持动态扩容

2、给storageclass添加allowVolumeExpansion字段

[root@192 ~]# kubectl  edit  storageclass default    

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: default
parameters:
  archiveOnDelete: "false"
provisioner: nfs-client-provisioner-default
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true   #增加该字段表示允许动态扩容
~                                                                                                                                          
"/tmp/kubectl-edit-x0fyj.yaml" 24L, 738C written
storageclass.storage.k8s.io/default edited
[root@192 ~]# 

3、再次修改pvc spec.resources.requests.storage字段

[root@192 ~]# kubectl edit pvc comom-store-column-03-24
spec:
  accessModes:
  - ReadWriteMany
  dataSource: null
  resources:
    requests:
      storage: 30Gi
  volumeName: pvc-24fc01a0-6d9b-11ea-9107-b8ca3a62236c
status:
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 10Gi
  phase: Bound
"/tmp/kubectl-edit-mibh7.yaml" 38L, 1180C written
persistentvolumeclaim/comom-store-column-03-24 edited
[root@192 ~]#
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学亮编程手记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值