简体   繁体   English

使用不同的 SubChart 升级 Helm

[英]Helm Upgrade with different SubChart

We have an helm chart with a subchart dependency, now in the latest release was decided to use a different subchart (same component) but from a different "vendor" (like Bitnami).我们有一个带有子图依赖关系的舵图,现在在最新版本中决定使用不同的子图(相同的组件)但来自不同的“供应商”(如 Bitnami)。

The problem is that when we run helm upgrade on a cluster, the installation succeed, but the old subchart components are not automatically removed and we have to "manually" run kubectl delete.问题是当我们在集群上运行 helm upgrade 时,安装成功,但是旧的 subchart 组件并没有被自动删除,我们必须“手动”运行 kubectl delete。

This creates a lot of Ops problem because it does not fit well with our GitOps approach.这会产生很多 Ops 问题,因为它不适合我们的 GitOps 方法。

There is a way to automatically remove all previous subchart component when doing an helm upgrade?有没有办法在进行 helm 升级时自动删除所有以前的子图组件?

This seems a normal scenario expecially today with a lot of charts hosted by different companies (like Bitnami, Quay ecc), without encountering lock-in.这似乎是一种正常的情况,尤其是今天,许多图表由不同的公司(如 Bitnami、Quay ecc)托管,而不会遇到锁定。

You can use Helm Conditions to easily specify which dependencies should be installed.您可以使用Helm 条件轻松指定应安装哪些依赖项。

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:我在Chart.yaml声明了两个依赖Chart.yaml并且在values.yaml文件中定义了只应安装redis

$ 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:让我们安装这个图表以确保只安装了redis

$ 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.从上面的输出中可以看出, memcached没有按预期安装。

Now suppose we want to install memcached instead of redis .现在假设我们要安装memcached而不是redis All we need to do is change memcached.enabled and redis.enabled in the values.yaml file and upgrade the release:我们需要做的就是更改values.yaml文件中的memcached.enabledredis.enabled并升级版本:

$ 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.一切似乎都很好,卸载了redis并安装了memcached

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM