How to apply helm chart to existing resources?
Asked Answered
E

3

8

Is there any way to apply a helm chart to existing resources?

Eg: I have already created a namespace manually and now I want to "helmify" it. But when I add a new template file to my chart and run helm upgrade I get an error:

Error: UPGRADE FAILED: no Namespace with the name "ingress-haproxy" found

I saw this issue but it's not very helpful: https://github.com/kubernetes/helm/issues/1999

Earwax answered 19/2, 2018 at 17:11 Comment(1)
can you give more details (preferably code sample) on your chart/template. does the chart attempt to create the namespace? or do what?Credible
M
4

Yes, you can import existing resources to your helm chart. I only test with helm3 so maybe there a difference on other versions that need you to discover.

  1. Create your helm revision (without existing resources).
  2. Adding the labels and annotations of existing resource as below
annotations:
  meta.helm.sh/release-name: <release-name>
  meta.helm.sh/release-namespace: <your namespace>

labels:
  app.kubernetes.io/managed-by: Helm
  1. helm upgrade <release>
Mucilage answered 28/12, 2020 at 11:0 Comment(0)
D
1

Is the manually created namespace named "ingress-haproxy" ?

From the error you're getting it seems:

  1. the namespace does not exist (maybe it has a slightly different name)..
  2. you've previously ran helm install since otherwise it would have complained about the inexistent helm release name.

Anyway, for now, the answer is no, helm does not support ignoring existing resources. You can follow this issue for any updates : https://github.com/helm/helm/issues/4824

Currently your only chance is to remove all objects and have them recreated via helm install. If this is not acceptable, leave them in place and manage them via kubectl apply and manage all your other objects via helm charts.

Doxy answered 11/6, 2019 at 23:33 Comment(0)
R
0

you can do this by patching existing resources with release name and release namespace

kubectl patch deployment my-app \-n default \
--patch '{"metadata": {"annotations": {"meta.helm.sh/release-name": "release", "meta.helm.sh/release-namespace": "release-namespace"}, "labels": {"app.kubernetes.io/managed-by": "Helm"}}}'

and then run :

helm update --install -n release-namespace release ...
Rydder answered 20/8, 2024 at 15:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.