Can a Persistent Volume be resized?

前端 未结 6 1763
悲哀的现实
悲哀的现实 2020-12-23 10:05

I\'m running a MySQL deployment on Kubernetes however seems like my allocated space was not enough, initially I added a persistent volume of 50GB and now I\'d l

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 10:34

    There is some support for this in 1.8 and above, for some volume types, including gcePersistentDisk and awsBlockStore, if certain experimental features are enabled on the cluster.

    For other volume types, it must be done manually for now. In addition, support for doing this automatically while pods are online (nice!) is coming in a future version (currently slated for 1.11):

    For now, these are the steps I followed to do this manually with an AzureDisk volume type (for managed disks) which currently does not support persistent disk resize (but support is coming for this too):

    1. Ensure PVs have reclaim policy "Retain" set.
    2. Delete the stateful set and related pods. Kubernetes should release the PVs, even though the PV and PVC statuses will remain Bound. Take special care for stateful sets that are managed by an operator, such as Prometheus -- the operator may need to be disabled temporarily. It may also be possible to use Scale to do one pod at a time. This may take a few minutes, be patient.
    3. Resize the underlying storage for the PV(s) using the Azure API or portal.
    4. Mount the underlying storage on a VM (such as the Kubernetes master) by adding them as a "Disk" in the VM settings. In the VM, use e2fsck and resize2fs to resize the filesystem on the PV (assuming an ext3/4 FS). Unmount the disks.
    5. Save the JSON/YAML configuration of the associated PVC.
    6. Delete the associated PVC. The PV should change to status Released.
    7. Edit the YAML config of the PV, after which the PV status should be Available:
      1. specify the new volume size in spec.capacity.storage,
      2. remove the spec.claimref uid and resourceVersion fields, and
      3. remove status.phase.
    8. Edit the saved PVC configuration:
      1. remove the metadata.resourceVersion field,
      2. remove the metadata pv.kubernetes.io/bind-completed and pv.kubernetes.io/bound-by-controller annotations, and
      3. change the spec.resources.requests.storage field to the updated PV size, and
      4. remove all fields inside status.
    9. Create a new resource using the edited PVC configuration. The PVC should start in Pending state, but both the PV and PVC should transition relatively quickly to Bound.
    10. Recreate the StatefulSet and/or change the stateful set configuration to restart pods.

提交回复
热议问题