Use case
"I want to deploy elasticsearch + kibana, by using elastic official helm charts. I want to create a helm chart called data-viz with these charts as dependency."
Running helm install data-viz --set cluster=toto
must create an elasticsearch cluster "toto", and a kibana configured with elasticsearchHosts
= toto.
Problem
I see here https://github.com/helm/helm/blob/master/docs/chart_template_guide/subcharts_and_globals.md it's possible to configure sub-chart from main-chart values.yml
. But I would like templatize sub-chart values.yml from main-chart values.yaml, is it possible?
I was thinking to something simple as:
.
├── Chart.yaml
├── charts
│ ├── elasticsearch
│ │ ├── Chart.yaml
│ │ └── templates
│ │ └── values.yaml
│ ├── elasticsearch-7.4.0.tgz
│ └── kibana-7.4.0.tgz
├── requirements.lock
├── requirements.yaml
└── values.yaml
Hack solution
A small Python script that creates the values.yaml
file from sub-chart/values-template.yaml
+ data.
You can use a --values flag in your Helm commands to override the values in a chart and pass in a new file. Specify the name of the new file after the --values flag in the Helm command. Example: helm upgrade --install <service> -f values.
To perform a helm release upgrade using the CLI, run the following command provided: helm upgrade <release name> <chart directory> -f my-values. yaml using the configuration specified in the customized values. yaml file. After a successful upgrade, the helm will return the following message.
With Helm's helm template command, you can check the output of the chart in fully rendered Kubernetes resource templates. This is a very handy command to check the templates' outputs, especially when you are developing a new chart, making changes to the chart, debugging, and so on.
The PR 6876 "feat(helm): Adding values templates in order to customize values with go-template, for the chart and its dependencies" could be of interest:
There have been many requests for a way to use templates for chart values.yaml (#2492, #2133, ...).
The main reason being that it's currently impossible to derive the values of the subcharts from templates.However, having templates in
values.yaml
make them unparsable and create a "chicken or the egg" problem when rendering them.This merge request creates an intuitive solution without such a problem: an optional
values/
directory which templates are rendered usingvalues.yaml
, and then merge them with it.
Thosevalues/
templates are only required for specific cases, work the same way astemplates/
templates, andvalues.yaml
will remain the main parsable source of value.The rendering order has also been changed to allow those new values to enable or disable dependencies, and to avoid rendering values templates of disabled dependencies.
New possibilities:
Can now customize dependencies values, which was previously totally impossible
subchart:
fullnameOverride: subchart-{{ .Relese.Name }}
debug: {{ default "false" .Values.debug }}
Can derive dependencies conditions from values
dependencies:
- name: subchart
condition: subchart.enabled
subchart:
{{- if eq .Values.environment "production" -}}
enabled: true
{{- else -}}
enabled: false
{{- end -}}
Similarly, PR 8580 "Added support to pass values to sub-charts via map.yaml
" is of interest
This PR allows developers to declare a
map.yaml
file on their chart, which can be used to map values invalues.yaml
to derived values that are used in templating, including sub-charts (see #8576 for the long explanation).This allows developers to write e.g.
apiVersion: v1
description: Chart with map and subcharts
name: chart-with-map
version: 0.0.1
dependencies:
- name: backend
version: 0.0.1
- name: frontend
version: 0.0.1
domain: example.com
backend:
uri: {{ printf "https://api.%s" .Values.domain }}
frontend:
uri: {{ printf "https://app.%s" .Values.domain }}
other_uri: {{ printf "https://blabla.%s" .Values.domain }}
thereby not having to expose backend: uri, frontend: uri in values.yaml (for the subchart), nor ask chart users to have to pass the same value in multiple keys for consistency (or use global names that lead to naming collisions).
I.e. it allows subcharts to be populated with derived (or maped) values without exposing these values to values.yaml (the public interface of the chart).
This is being implemented/evaluated in:
But that will likely require an HIP (Helm Improvement Proposal).
Update Feb. 2021: PR 6876 confirms in this comment a formal proposal is needed.
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