简体   繁体   English

收缩 Kubernetes 持久卷

[英]Shrink Kubernetes persistent volumes

I do have multiple persistent volumes which need to be shrinked to reduce the hosting costs.我确实有多个持久卷需要缩小以降低托管成本。 I already figured out that Kubernetes does not provide such an option.我已经发现 Kubernetes 不提供这样的选项。 I also tried to clone or the restore the volumes from an snapshot to a new smaller volume - with the same result ( requested volume size XXX is less than the size XXX for the source snapshot ).我还尝试将卷从快照克隆或还原到新的较小卷 - 结果相同( requested volume size XXX is less than the size XXX for the source snapshot )。

Nevertheless I need a solution or workaround to get this done.不过,我需要一个解决方案或解决方法来完成这项工作。

The cluster is deployed with Rancher and the volumes are mounted to a Ceph Cluster.集群使用 Rancher 部署,卷挂载到 Ceph 集群。 Everything is provided by an external hoster.一切都由外部主机提供。

It is a bit tricky, but I would try to create the volumes manually with the proper size, fill them with the data from the bigger volumes and then redeploy having the application attach to the new volumes.这有点棘手,但我会尝试手动创建具有适当大小的卷,用更大卷中的数据填充它们,然后重新部署让应用程序附加到新卷。

I know that the answer is pretty generic but how to do it will depend on what capabilities and access to the underlying infrastructure you have.我知道答案很笼统,但如何做到这一点将取决于您拥有的功能和对底层基础架构的访问权限。

I'm not familiar with Ceph backed volumes but if you are able to create the new ones in Ceph, copy from the bigger volumes to the new ones directly within Ceph and then create the PV manually but configured to use the smaller volumes (so it does not provision the Ceph storage when creating the PV) that would probably be the easiest option.我不熟悉 Ceph 支持的卷,但如果您能够在 Ceph 中创建新卷,请直接在 Ceph 中从较大的卷复制到新卷,然后手动创建 PV,但配置为使用较小的卷(所以它创建 PV 时不配置 Ceph 存储),这可能是最简单的选择。

Finally I achieved what needed with the following steps (still tricky and manual work):最后,我通过以下步骤实现了所需(仍然很棘手和手动工作):

  • Stop running pod (otherwhise you could not use the volume in the next steps)停止运行 pod(否则您无法在后续步骤中使用该卷)
  • Create the a new PVC with the desired capacity (ensure that the spec and label matches the exisitng PVC)创建具有所需容量的新 PVC(确保规格和 label 与现有 PVC 匹配)
  • Run this Job https://github.com/edseymour/pvc-transfer运行此作业https://github.com/edseymour/pvc-transfer
    • In the spec of the job-template.yaml set the source and destination volumejob-template.yaml的规范中。yaml 设置源卷和目标卷
  • Set the ReclaimPolicy on the new created pv to Retain.将新创建的 pv 上的 ReclaimPolicy 设置为 Retain。 This will ensure that the pv won't be deleted after we delete the temp pvc in the next step这将确保我们在下一步删除临时 pvc 后不会删除 pv
  • Delete the source and destination pvc删除源pvc和目标pvc
  • Create a new pvc with the old name and the new storage capacity使用旧名称和新存储容量创建新 pvc
  • On the new pv point the claimRef to the new pvc在新 pv 点上,将 claimRef 指向新 pvc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM