Search code examples
kuberneteskubernetes-helm

Helm Release with existing resources


Previously we only use helm template to generate the manifest and apply to the cluster, recently we start planning to use helm install to manage our deployment, but running into following problems:

Our deployment is a simple backend api which contains "Ingress", "Service", and "Deployment", when there is a new commit, the pipeline will be triggered to deploy. We plan to use the short commit sha as the image tag and helm release name. Here is the command helm upgrade --install releaseName repo/chartName -f value.yaml --set image.tag=SHA

This runs perfectly fine for the first time, but when I create another release it fails with following error message

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"

The error message is pretty clear on what the issue is, but I am just wondering what's "correct" way of using helm in this case?

It is not practical that I uninstall everything for a new release, and I also dont want to keep using the same release.


Solution

  • You are already doing it "right" way, just don't change release-name. That's key for Helm to identify resources. It seems that you previously used different name for release (rel-123) then you are using now (rel-124).

    To fix your immediate problem, you should be able to proceed by updating value of annotation meta.helm.sh/release-name on problematic resource. Something like this should do it:

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