Is there a way to conditionally install a helm subchart based on global values.yaml? I've all my internal services and components as subcharts, and one of them is a messagequeue chart. In my dev and test environment (local k8s), I use RabbitMQ, and in staging and Prod (AKS), I use Azure Service Bus. Based on the namespace/values.yaml, I want to install rabbitmq or not.
P.S - I've created all the components as subcharts so that they are all part of a single release.
You can use a --set flag in your Helm commands to override the value of a setting in the YAML file. Specify the name of the setting and its new value after the --set flag in the Helm command. The --set flag in the above command overrides the value for the <service>.
A subchart is considered "stand-alone", which means a subchart can never explicitly depend on its parent chart. For that reason, a subchart cannot access the values of its parent. A parent chart can override values for subcharts. Helm has a concept of global values that can be accessed by all charts.
The tpl function allows developers to evaluate strings as templates inside a template. This is useful to pass a template string as a value to a chart or render external configuration files.
The helm repo command group provides commands to add, list, and remove repositories. You can see which repositories are configured using helm repo list : $ helm repo list NAME URL stable https://charts.helm.sh/stable mumoshu https://mumoshu.github.io/charts.
Update: With helm 3.0 release and Chart version v2, the chart dependencies have to be added in Chart.yaml instead of a separate requirements.yaml file. So if you are using apiVersion=v2 in helm 3, see the helm v2->v3 changes. This would then be:
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
I've found out the answer:
In requirements.yaml, add:
dependencies: - name: api condition: api.enabled - name: messagequeue condition: messagequeue.enabled
and in values.yaml, add
api: enabled: true messagequeue: enabled: false
Now during installation, pass the values to enabled or disable the messagequeue as follows:
helm install --dry-run --debug website\ --set messagequeue.enabled=true
or
helm install --dry-run --debug website\ --set messagequeue.enabled=false
I was having this error.
helm chart with requirements.yaml, did not find local charts
"helm dep build" fails if requirements.yaml contains local dependencies and remote one #3742.
My solution was to:
charts/
(directory) to subcharts/
chmod 755 subcharts/*
Heml 3 didn't like it when I placed my local dependencies in charts/
Also Helm dep up needs permissions to move the local dependencies from your subcharts directory to tmpcharts/
and so on.
**
**
I read this from @sgandon :
Bug documented #3742.
comment.
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.
Note:
!! On Helm 3 requirements.yaml is deprecated. !!
You add the dependencies in the 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
Added my variables to my globals in the Parent/Main Values.yaml
globals: chart-you-want-to-deploy-1: enabled: true chart-you-want-to-deploy-2: enabled: false
Dont forget to add the flags to your command.
In my case I was using a CI/CD tool (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
my tree
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. - Thank you @Narayana and @sgandon . Thanks to you guys I'm happy deploying!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With