Helm Release 与现有资源

Helm Release with existing resources

以前我们只使用helm template生成manifest并应用到集群,最近我们开始计划使用helm install来管理我们的部署,但是运行遇到以下问题:

我们的部署是一个简单的后端api,包含“Ingress”、“Service”和“Deployment”,当有新的提交时,将触发管道进行部署。 我们计划使用简短的 commit sha 作为镜像标签和 helm 发布名称。这是命令 helm upgrade --install releaseName repo/chartName -f value.yaml --set image.tag=SHA

这第一次运行得很好,但是当我创建另一个版本时它失败并显示以下错误消息

rendered manifests contain a resource that already exists. Unable to continue with install: Service "app-svc" in namespace "ns" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-name" must equal "rel-124": current value is "rel-123"

错误消息非常清楚问题所在,但我只是想知道在这种情况下使用 helm 的“正确”方式是什么?

我为新版本卸载所有东西是不切实际的,我也不想继续使用同一个版本。

您已经以“正确”的方式做到了,只是不要改变 release-name。这是 Helm 识别资源的关键。似乎您以前使用不同的名称发布 (rel-123),然后您现在使用 (rel-124)。

要解决您眼前的问题,您应该能够通过更新有问题的资源上的注释 meta.helm.sh/release-name 的值来继续。应该这样做:

kubectl annotate --overwrite service app-svc meta.helm.sh/release-name=rel-124