動態擴容pvc


 

 

 

 

 最開始的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 ~]#

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM