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

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

问题描述

我正在尝试部署一个 helm chart,它使用 PersistentVolumeClaimStorageClass 来动态提供所需的 sotrage.这按预期工作,但我找不到任何允许像

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 保留磁盘,但 helm 将删除 PVC 并孤立它们.注释 PVC 以便 helm 不会删除它们可以解决此问题,但是运行 install 会导致错误

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.

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

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 将不再以任何方式管理它.如果在已删除但保留资源的版本上使用 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 并设置Retain"该卷的政策如下:
  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

  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

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

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 重用动态配置的 PersistentVolume?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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