Helm 有条件地安装子图
Helm conditionally install subchart
有没有办法根据全局 values.yaml 有条件地安装 helm 子图?我将所有内部服务和组件都作为子图表,其中之一是消息队列图表。在我的开发和测试环境(本地 k8s)中,我使用 RabbitMQ,在暂存和生产 (AKS) 中,我使用 Azure 服务总线。基于namespace/values.yaml,我要不要安装rabbitmq
P.S - 我已将所有组件创建为子图,以便它们都是单个版本的一部分。
更新:
使用 helm 3.0 版本和 Chart 版本 v2,必须在 Chart.yaml 中添加图表依赖项,而不是单独的 requirements.yaml 文件。因此,如果您在 helm 3 中使用 apiVersion=v2,请参阅 helm v2->v3 changes。这将是:
apiVersion: v2
name: myapplication
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.0
dependencies:
- name: apidocs
condition: apidocs.enabled
我找到答案了:
在requirements.yaml中添加:
dependencies:
- name: api
condition: api.enabled
- name: messagequeue
condition: messagequeue.enabled
并在 values.yaml 中添加
api:
enabled: true
messagequeue:
enabled: false
现在在安装过程中,将值传递给启用或禁用消息队列,如下所示:
helm install --dry-run --debug website\ --set messagequeue.enabled=true
或
helm install --dry-run --debug website\ --set messagequeue.enabled=false
我建议这个(丑陋的)解决方法作为从 @sgandon: https://github.com/helm/helm/issues/3742#issuecomment-383095917
借来的答案
dependencies:
- name: mobi-postgresql
version: 1.0.1
repository: "@mobi"
alias: postgresql
- name: oraclepdb
version: 0.0.1
repository: "file://subcharts/oraclepdb"
condition: oraclepdb.enabled
然后您可以使用实践Chart dependencies 通过helm dep update
和helm dep build
.
将子图作为依赖项进行管理
只要this bug不固定就不美
使用 Helm 版本 v3.4.1.
我遇到了这个错误。
"helm dep build" fails if requirements.yaml contains local dependencies and remote one #3742.
我的解决方案是:
- 将
charts/
(目录)重命名为 subcharts/
- 和
chmod 755 subcharts/*
当我将本地依赖项放在 charts/
中时,Heml 3 不喜欢它
此外,Helm dep up 需要权限才能将本地依赖项从您的子图表目录移动到 tmpcharts/
等等。
**
这不是我的发现。
**
我是从@sgandon 那里读到的:
the reason why the os.Stat() fails to find the folder. This is
because the calling function
downloadAll is renaming the charts folder to tmpcharts during the update
thus making our unpacked chart not foundable for that duration.
注:
!!在 Helm 3 上 requirements.yaml 已弃用。 !!
您在 Parent/Main Charts.yaml.
添加依赖项
dependencies:
- name: chart-you-want-to-deploy-1
repository: file://subcharts/chart-you-want-to-deploy-1
version: 0.0.1
condition: chart-you-want-to-deploy-1.enabled
- name: chart-you-want-to-deploy-2
repository: file://subcharts/chart-you-want-to-deploy-2
version: 0.0.1
condition: chart-you-want-to-deploy-2e.enabled
将我的变量添加到 Parent/Main Values.yaml
中的全局变量
globals:
chart-you-want-to-deploy-1:
enabled: true
chart-you-want-to-deploy-2:
enabled: false
不要忘记将标志添加到您的命令中。
就我而言,我使用的是 CI/CD 工具 (Gitlab)
script:
- >
helm dep up Main-Chart-Name && \
helm upgrade --install \
--set chart-you-want-to-deploy-1.enabled=false \
--set chart-you-want-to-deploy-2.enabled=true \
RELEASE_NAME Main-Chart-Name
我的树
Main-Chart-Name
├── Chart.yaml
├── subcharts
│ ├── chart-you-want-to-deploy-1
│ │ ├── Chart.yaml
│ │ ├── charts
│ │ ├── templates
│ │ │ └── chart-you-want-to-deploy-1.yaml
│ │ └── values.yaml
│ └── chart-you-want-to-deploy-2
│ ├── Chart.yaml
│ ├── charts
│ ├── templates
│ │ └── chart-you-want-to-deploy-2.yaml
│ └── values.yaml
├── templates
│ ├── helpers.tpl
│ ├── my.yaml
│ ├── main.yaml
│ └── templates.yaml
└── values.yaml
P.S。 - 谢谢@Narayana 和@sgandon。感谢你们,我很高兴部署!
有没有办法根据全局 values.yaml 有条件地安装 helm 子图?我将所有内部服务和组件都作为子图表,其中之一是消息队列图表。在我的开发和测试环境(本地 k8s)中,我使用 RabbitMQ,在暂存和生产 (AKS) 中,我使用 Azure 服务总线。基于namespace/values.yaml,我要不要安装rabbitmq
P.S - 我已将所有组件创建为子图,以便它们都是单个版本的一部分。
更新: 使用 helm 3.0 版本和 Chart 版本 v2,必须在 Chart.yaml 中添加图表依赖项,而不是单独的 requirements.yaml 文件。因此,如果您在 helm 3 中使用 apiVersion=v2,请参阅 helm v2->v3 changes。这将是:
apiVersion: v2
name: myapplication
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.0
dependencies:
- name: apidocs
condition: apidocs.enabled
我找到答案了:
在requirements.yaml中添加:
dependencies:
- name: api
condition: api.enabled
- name: messagequeue
condition: messagequeue.enabled
并在 values.yaml 中添加
api:
enabled: true
messagequeue:
enabled: false
现在在安装过程中,将值传递给启用或禁用消息队列,如下所示:
helm install --dry-run --debug website\ --set messagequeue.enabled=true
或
helm install --dry-run --debug website\ --set messagequeue.enabled=false
我建议这个(丑陋的)解决方法作为从 @sgandon: https://github.com/helm/helm/issues/3742#issuecomment-383095917
借来的答案dependencies:
- name: mobi-postgresql
version: 1.0.1
repository: "@mobi"
alias: postgresql
- name: oraclepdb
version: 0.0.1
repository: "file://subcharts/oraclepdb"
condition: oraclepdb.enabled
然后您可以使用实践Chart dependencies 通过helm dep update
和helm dep build
.
只要this bug不固定就不美
使用 Helm 版本 v3.4.1.
我遇到了这个错误。
"helm dep build" fails if requirements.yaml contains local dependencies and remote one #3742.
我的解决方案是:
- 将
charts/
(目录)重命名为subcharts/
- 和
chmod 755 subcharts/*
当我将本地依赖项放在 charts/
中时,Heml 3 不喜欢它
此外,Helm dep up 需要权限才能将本地依赖项从您的子图表目录移动到 tmpcharts/
等等。
**
这不是我的发现。
**
我是从@sgandon 那里读到的:
the reason why the os.Stat() fails to find the folder. This is because the calling function downloadAll is renaming the charts folder to tmpcharts during the update thus making our unpacked chart not foundable for that duration.
注:
!!在 Helm 3 上 requirements.yaml 已弃用。 !!
您在 Parent/Main Charts.yaml.
添加依赖项dependencies:
- name: chart-you-want-to-deploy-1
repository: file://subcharts/chart-you-want-to-deploy-1
version: 0.0.1
condition: chart-you-want-to-deploy-1.enabled
- name: chart-you-want-to-deploy-2
repository: file://subcharts/chart-you-want-to-deploy-2
version: 0.0.1
condition: chart-you-want-to-deploy-2e.enabled
将我的变量添加到 Parent/Main Values.yaml
中的全局变量globals:
chart-you-want-to-deploy-1:
enabled: true
chart-you-want-to-deploy-2:
enabled: false
不要忘记将标志添加到您的命令中。
就我而言,我使用的是 CI/CD 工具 (Gitlab)
script:
- >
helm dep up Main-Chart-Name && \
helm upgrade --install \
--set chart-you-want-to-deploy-1.enabled=false \
--set chart-you-want-to-deploy-2.enabled=true \
RELEASE_NAME Main-Chart-Name
我的树
Main-Chart-Name
├── Chart.yaml
├── subcharts
│ ├── chart-you-want-to-deploy-1
│ │ ├── Chart.yaml
│ │ ├── charts
│ │ ├── templates
│ │ │ └── chart-you-want-to-deploy-1.yaml
│ │ └── values.yaml
│ └── chart-you-want-to-deploy-2
│ ├── Chart.yaml
│ ├── charts
│ ├── templates
│ │ └── chart-you-want-to-deploy-2.yaml
│ └── values.yaml
├── templates
│ ├── helpers.tpl
│ ├── my.yaml
│ ├── main.yaml
│ └── templates.yaml
└── values.yaml
P.S。 - 谢谢@Narayana 和@sgandon。感谢你们,我很高兴部署!