0

We have a helm chart with a subchart dependency. Now, in the latest release it was decided to use a different subchart (same component) but from a different "vendor" (like Bitnami).

The problem is that when we run helm upgrade on a cluster, the installation succeeds but the old subchart components are not automatically removed and we have to "manually" run kubectl delete.

This creates a lot of Ops problem because it does not fit well with our GitOps approach.

There is a way to automatically remove all previous subchart component when doing an helm upgrade?

This seems a normal scenario especially today with a lot of charts hosted by different companies (like Bitnami, Quay ecc), without encountering lock-in.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Slevin
  • 141
  • 1
  • 8
  • What chart was used? Is it public or selfmade? What are new chart and subchart? What resources were created and now are not deleted? – moonkotte Oct 29 '21 at 09:52
  • We have a chart, that originally as subchart was using: https://github.com/kubernetes/ingress-nginx/tree/main/charts/ingress-nginx Now we change subchart to the Bitnami one: https://github.com/bitnami/charts/tree/master/bitnami/nginx-ingress-controller – Slevin Nov 04 '21 at 18:16

1 Answers1

0

You can use Helm Conditions to easily specify which dependencies should be installed.

I've created an example to illustrate how it works.

I have two dependencies declared in the Chart.yaml and I've defined in the values.yaml file that only redis should be installed:

$ cat test-chart/Chart.yaml                                                                                                                    
...
dependencies:
- name: redis
  version: "15.x.x"
  repository: "https://charts.bitnami.com/bitnami"
  condition: redis.enabled
- name: memcached
  version: "5.x.x"
  repository: "https://charts.bitnami.com/bitnami"
  condition: memcached.enabled

$ cat test-chart/values.yaml
...
redis:
  enabled: true
memcached:
  enabled: false

Let's install this chart to make sure only redis is installed:

$ helm install chart-1 test-chart
NAME: chart-1
LAST DEPLOYED: Wed Nov 10 11:18:44 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

$ kubectl get pods
NAME                       READY   STATUS    RESTARTS   AGE
chart-1-redis-master-0     1/1     Running   0          107s
chart-1-redis-replicas-0   1/1     Running   0          107s
chart-1-redis-replicas-1   1/1     Running   0          66s
chart-1-redis-replicas-2   1/1     Running   0          32s

As you can see from the above output, memcached wasn't installed as expected.

Now suppose we want to install memcached instead of redis. All we need to do is change memcached.enabled and redis.enabled in the values.yaml file and upgrade the release:

$ cat test-chart/values.yaml
...
redis:
  enabled: false
memcached:
  enabled: true

$ helm upgrade chart-1 test-chart
Release "chart-1" has been upgraded. Happy Helming!
NAME: chart-1
LAST DEPLOYED: Wed Nov 10 11:21:49 2021
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None

$ kubectl get pods
NAME                                 READY   STATUS    RESTARTS   AGE
chart-1-memcached-86847c8c4f-nt5wv   1/1     Running   0          21s

Everything seems fine, redis was uninstalled and memcached was installed.

matt_j
  • 4,010
  • 1
  • 9
  • 23
  • Hi, we actually found that our issues was that our helm was pushed on Helm Repository with the /charts folder, and it was containing both version of Nginx (bitnami and k8s.gcr.io)..Removed it and it started working – Slevin Nov 16 '21 at 09:23