Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helm conditionally install subchart

Tags:

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.

like image 640
Narayana Avatar asked Jan 04 '19 04:01

Narayana


People also ask

How do I override Subchart values helm?

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>.

What is a helm Subchart?

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.

What is TPL in Helm?

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.

What is Helm repo add?

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.


2 Answers

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 
like image 81
Narayana Avatar answered Oct 26 '22 15:10

Narayana


Using Helm version v3.4.1.

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:

  • Rename charts/ (directory) to subcharts/
  • And 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.

**

This is not my find.

**

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!

like image 37
Raposo Avatar answered Oct 26 '22 14:10

Raposo