【问题标题】:Helm not deleting all the related resources of a chartHelm 没有删除图表的所有相关资源
【发布时间】:2021-03-03 02:40:07
【问题描述】:

我有一个部署不成功的 helm 版本。我尝试卸载它,以便创建一个新的。 我发现的奇怪的事情是,由于部署失败,部分创建了一些资源(几个作业),使用 helm 卸载失败的部署并不会删除那些部分创建的资源,这可能会在我尝试安装版本时导致问题再次进行一些更改。

我的问题是:有没有办法让 helm 彻底删除一个版本的所有相关资源。

【问题讨论】:

  • 提供更多信息,比如那些部分创建的东西是什么?
  • 在我的例子中,那些部分创建的东西是图表安装创建的工作。

标签: kubernetes-helm


【解决方案1】:

由于没有关于部分创建的资源的详细信息。一种情况可能是 helm uninstall/delete 不会删除命名空间中的 PVC。我们通过创建一个单独的命名空间来部署应用程序解决了这个问题,并且 helm release 被卸载/删除,我们也删除了命名空间。对于全新部署,再次创建命名空间并在命名空间上进行 helm 安装以进行全新安装您还可以在创建 storageClass 时将 reclaimPolicy 更改为“Delete”(默认情况下 Reclaimpolicy 为保留)如下文所述

舵机上的 PVC 问题:https://github.com/goharbor/harbor-helm/issues/268#issuecomment-505822451

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
   name: rook-ceph-block
provisioner: ceph.rook.io/block
parameters:
  blockPool: replicapool
  # The value of "clusterNamespace" MUST be the same as the one in which your rook cluster exist
  clusterNamespace: rook-ceph-system
  # Specify the filesystem type of the volume. If not specified, it will use `ext4`.
# Optional, default reclaimPolicy is "Delete". Other options are: "Retain", "Recycle" as documented in https://kubernetes.io/docs/concepts/storage/storage-classes/
reclaimPolicy: Delete

【讨论】:

    【解决方案2】:

    正如您在评论中所说,部分创建的对象是一项工作。在 helm 中有一个概念名称钩子,它还针对不同的情况运行作业,例如:预安装、安装后等。我认为你使用了其中之一。

    下面给出了一个示例的yaml,您可以在其中设置"helm.sh/hook-delete-policy": hook-failed而不是hook-succeeded,然后如果挂钩失败,作业将被删除。更多内容请看helm hook官方文档

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: {{ .Release.Name | quote }}
      labels:
        app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
        app.kubernetes.io/instance: {{ .Release.Name | quote }}
      annotations:
        # This is what defines this resource as a hook. Without this line, the
        # job is considered part of the release.
        "helm.sh/hook": pre-install
        "helm.sh/hook-weight": "-5"
        "helm.sh/hook-delete-policy": hook-succeeded
    spec:
      template:
        metadata:
          name: {{ .Release.Name | quote }}
          labels:
            app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
            app.kubernetes.io/instance: {{ .Release.Name | quote }}
        spec:
          restartPolicy: Never
          containers:
            - name: pre-install-job
              image: "ubuntu"
              #command: ["/bin/sleep","{{ default "10" .Values.hook.job.sleepyTime }}"]
              args:
                - /bin/bash
                - -c
                - echo
                - "pre-install hook"
    

    【讨论】:

      猜你喜欢
      • 2021-01-27
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      • 2022-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      相关资源
      最近更新 更多