如何在GKE上通过Helm重新使用动态预配置的PersistentVolumes? [英] How can you reuse dynamically provisioned PersistentVolumes with Helm on GKE?

查看:218
本文介绍了如何在GKE上通过Helm重新使用动态预配置的PersistentVolumes?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署一个使用PersistentVolumeClaimStorageClass来动态配置所需的储备表的Helm图表.这可以按预期工作,但是我找不到任何允许工作流之类的配置

I am trying to deploy a helm chart which uses PersistentVolumeClaim and StorageClass to dynamically provision the required sotrage. This works as expected, but I can't find any configuration which allows a workflow like

helm delete xxx

# Make some changes and repackage chart

helm install --replace xxx

我不想一直运行该发行版,并且希望将来在部署中重用该存储.

I don't want to run the release constantly, and I want to reuse the storage in deployments in the future.

将存储类设置为reclaimPolicy: Retain会保留磁盘,但掌舵将删除PVC并将其孤立.注释PVC,以便掌舵不会将其删除可解决此问题,但随后运行安装会导致错误

Setting the storage class to reclaimPolicy: Retain keeps the disks, but helm will delete the PVC and orphan them. Annotating the PVC's so that helm does not delete them fixes this problem, but then running install causes the error

Error: release xxx failed: persistentvolumeclaims "xxx-xxx-storage" already exists

我认为我误解了掌控发布中的一些基本知识.也许根本不应该在图表中创建卷.

I think I have misunderstood something fundamental to managing releases in helm. Perhaps the volumes should not be created in the chart at all.

推荐答案

PersistenVolumeClain 仅在您的实际 PersistentVolume 和您的广告连播之间创建一个映射.

PersistenVolumeClain creating just a mapping between your actual PersistentVolume and your pod.

对PV使用"helm.sh/resource-policy": keep注释不是最好的主意,因为

Using "helm.sh/resource-policy": keep annotation for PV is not the best idea, because of that remark in a documentation:

注释"helm.sh/resource-policy":keep指示Tiller在删除helm的过程中跳过此资源.但是,此资源成为孤立的.头盔将不再以任何方式对其进行管理.如果在已删除但已保留资源的发行版上使用helm install --replace,可能会导致问题.

The annotation "helm.sh/resource-policy": keep instructs Tiller to skip this resource during a helm delete operation. However, this resource becomes orphaned. Helm will no longer manage it in any way. This can lead to problems if using helm install --replace on a release that has already been deleted, but has kept resources.

如果要在删除发行版之后手动创建PV,Helm将删除PVC,PVC将标记为可用",并且在下一次部署时,它将重新使用它.实际上,您不需要将PVC保留在群集中即可保留数据.但是,要使其始终使用相同的PV,您需要使用标签和选择器.

If you will create a PV manually after you will delete your release, Helm will remove PVC, which will be marked as "Available" and on next deployment, it will reuse it. Actually, you don't need to keep your PVC in the cluster to keep your data. But, for making it always using the same PV, you need to use labels and selectors.

对于保留和重用卷,您可以:

For keep and reuse volumes you can:

  1. 创建带有标签的PersistenVolume,例如,for_app=my-app并为该卷设置保留"策略,如下所示:
  1. Create PersistenVolume with the label, as an example, for_app=my-app and set "Retain" policy for that volume like this:

apiVersion: v1 kind: PersistentVolume metadata: name: myappvolume namespace: my-app labels: for_app: my-app spec: persistentVolumeReclaimPolicy: Retain capacity: storage: 5Gi accessModes: - ReadWriteOnce

apiVersion: v1 kind: PersistentVolume metadata: name: myappvolume namespace: my-app labels: for_app: my-app spec: persistentVolumeReclaimPolicy: Retain capacity: storage: 5Gi accessModes: - ReadWriteOnce

  1. 在Helm中修改PersistenVolumeClaim配置.您需要添加一个选择器,以仅使用带有标签for_app=my-app的PersistenVolumes.
  1. Modify your PersistenVolumeClaim configuration in Helm. You need to add a selector for using only PersistenVolumes with a label for_app=my-app.

apiVersion: v1 kind: PersistentVolumeClaim metadata: name: myappvolumeclaim namespace: my-app spec: selector: matchLabels: for_app: my-app accessModes: - ReadWriteOnce resources: requests: storage: 5Gi

apiVersion: v1 kind: PersistentVolumeClaim metadata: name: myappvolumeclaim namespace: my-app spec: selector: matchLabels: for_app: my-app accessModes: - ReadWriteOnce resources: requests: storage: 5Gi

因此,现在您的应用程序每次启动时将使用相同的卷.

So, now your application will use the same volume each time when it started.

但是,请记住,您可能需要在相同名称空间中为其他应用使用选择器,以防止选择器使用您的PV.

But, please keep in mind, you may need to use selectors for other apps in the same namespace for preventing using your PV by them.

这篇关于如何在GKE上通过Helm重新使用动态预配置的PersistentVolumes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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