增大Kubernetes上永久磁盘的大小 [英] Increasing size of persistent disks on kubernetes

查看:125
本文介绍了增大Kubernetes上永久磁盘的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个使用10G的PersistentVolumeClaim部署在kubernetes上的单节点数据库服务(PostgreSQL,MySQL等),该服务将在GKE或AWS或Azure上运行(这并不重要).将磁盘扩展到20G的步骤是什么?例如,是否有办法将PVC绑定到现有磁盘(10G磁盘的快照)或类似的东西?

Suppose I have a one node Database service (PostgreSQL, MySQL, whatever...) deployed on kubernetes using a PersistentVolumeClaim of 10G That will be running on GKE or AWS or Azure (It does not really matter). What is the procedure to scale up the disk to 20G? Is there a way, for instance, to have a PVC bind to a existing disk (a snapshot of the 10G disk) or something like that?

我想要的是增加属于PVC的磁盘的存储大小并维护旧数据(该磁盘不一定是数据库,因此我不希望还原数据库备份或类似的东西. ).

What I want is to increase the storage size of a disk that belongs to a PVC AND maintain the old data (the disk will not necessarily be a database, so I'm not looking to restore a database backup or something like that).

我正在寻找类似的东西:拍摄旧磁盘的快照,从快照中创建更大的磁盘,然后使PVC使用新磁盘".

I'm looking for something like: take a snapshot of the old disk, create a bigger disk from the snapshot and "make the PVC use the new disk".

谢谢

推荐答案

您的PVC的PV为10G.您想要增加其大小.不幸的是,目前尚不支持调整大小.因此,您需要创建20G大小的新PVC.

You have a PVC with PV 10G. You want to increase its size. Unfortunately resize is not supported yet. So, you need to create new PVC with 20G size.

比方说,您现有的10G PVC称为older.

Lets say, your existing PVC with 10G called older.

请按照以下步骤操作:

第1步:用20G创建新的PVC,可以称其为latest.

Step 1: Create new PVC with 20G, lets say its called latest.

第2步:安装older& latest都放在一个容器中.将数据从older复制到latest.

Step 2: Mount older & latest both in a container. Copy data from older to latest.

步骤3:删除PVC older,我们不再需要older.数据已复制到latest PV.

Step 3: Delete PVC older, we do not need older any more. Data copied to latest PV.

步骤4:使latest的PV可用.

$ kubectl get pvc latest
NAME      STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
latest    Bound     pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            standard       30s

编辑PV pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6,将persistentVolumeReclaimPolicy设置为Retain.这样删除PVC不会删除PV.

Edit PV pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6 to set persistentVolumeReclaimPolicy to Retain. So that deleting PVC will not delete PV.

现在,删除PVC latest.

Now, delete PVC latest.

$ kubectl delete pvc latest

$ kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS     CLAIM            STORAGECLASS   REASON    AGE
pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            Retain           Released   default/latest   standard                 3m

查看状态,PV已释放.

See the status, PV is Released.

现在,使此latest PV可供另一个PVC声明,即我们的older,因为我们要在此PVC older下使用20G.

Now, make this latest PV available to be claimed by another PVC, our older as we want to use 20G under this PVC older.

再次编辑PV以删除ClaimRef

Edit PV again to remove claimRef

$ kubectl edit pv pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6

$ kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM     STORAGECLASS   REASON    AGE
pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            Retain           Available             standard                 6m

现在PV的状态为可用".

Now the status of PV is Available.

步骤5 :通过older PVC声明latest PV

Step 5: Claim latest PV by older PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: older
spec:
  accessModes:
    - ReadWriteOnce
  volumeName: pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6
  resources:
    requests:
      storage: 10Gi

使用volumeName pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6

Use volumeName pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6

$ kubectl get pvc,pv
NAME          STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc/older   Bound     pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            standard       9s

NAME                                          CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS    CLAIM            STORAGECLASS   REASON    AGE
pv/pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6   10Gi       RWO            Retain           Bound     default/older   standard                 9m

最后::将persistentVolumeReclaimPolicy设置为Delete

Finally: Set persistentVolumeReclaimPolicy to Delete

这就是您的PVC olderlatest PV为20G的方式.

This is how, your PVC older has had latest PV with 20G.

这篇关于增大Kubernetes上永久磁盘的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆