是否可以重命名PVC?我似乎找不到可能的证据。
我正试图缓解一个“设备没有剩余空间”的问题,我只是偶然发现了。基本上我的计划要求我调整卷的大小,我的服务会保留其数据。
不幸的是,我仍然在GKE上使用Kubernetes 1.8.6。它没有启用PersistentVolumeClaimResize
许可插件:
因此我必须手动保存数据。我制定了以下计划:
有问题的PVC附加到StatefulSet,因此旧名称和新名称必须匹配(因为StatefulSet期望遵循卷命名约定)。
但我不明白如何重命名持久量声明。
答案 0 :(得分:5)
The answer of your question is NO. There is no way to change any meta name in Kubernetes.
But, there is a way to fulfill your requirement.
You want to claim your new bigger PersistentVolume by old PersistentVolumeClaim.
Lets say, old PVC named victim
and new PVC named bigger
. You want to claim PV created for bigger
by victim
PVC. Because your application is already using victim
PVC.
Follow these steps to do the hack.
Step 1: Delete your old PVC victim
.
Step 2: Make PV of bigger
Available.
$ kubectl get pvc bigger
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
bigger Bound pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6 10Gi RWO standard 30s
Edit PV pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6
to set persistentVolumeReclaimPolicy to Retain
. So that deleting PVC will not delete PV.
Now, delete PVC bigger
.
$ kubectl delete pvc bigger
$ 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/bigger standard 3m
See the status, PV is Released.
Now, make this PV available to be claimed by another PVC, our victim
.
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
Now the status of PV is Available.
Step 3: Claim bigger
PV by victim
PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: victim
spec:
accessModes:
- ReadWriteOnce
volumeName: pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6
resources:
requests:
storage: 10Gi
Use volumeName pvc-8badc3c2-08c5-11e8-b07a-080027b3e1a6
kubectl get pvc,pv
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc/victim 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/victim standard 9m
Finally: Set persistentVolumeReclaimPolicy to Delete
This is how, your PVC victim
has had bigger PV.
答案 1 :(得分:1)
使用Kubernetes 1.11+,您可以通过简单地修改PVC的存储请求(https://kubernetes.io/blog/2018/07/12/resizing-persistent-volumes-using-kubernetes/)来执行按需调整大小。
GKE支持这一点(我已经使用过几次了),它非常简单,而且没有戏剧性。
答案 2 :(得分:0)
我无法对此进行验证,但我相当肯定,对于GKE,您可以转到Google云端控制台中的磁盘,找到PV使用的磁盘并在那里调整大小。完成后,您应该能够登录其附加的节点并在设备上运行resize2fs
。这很脏,但相当肯定这对我来说曾经有过一次。
您无需卸载或复制即可执行此操作,如果磁盘处于活动状态或较大,则可以节省您的时间。