'Using variables in values YAML file
I'm wondering what is the best way to pass input into a values.yaml file using a template.
I have a parent chart (called myapp for this example) defined which has the following dependencies:
myapp/requirements.yaml
dependencies:
- name: internaldep
condition: internaldep.enabled
repository: file://../internaldep
version: 0.1.0
- name: kafka
condition: kafka.enabled
repository: https://charts.bitnami.com
version: 6.1.6
In my case, both the internaldep chart (which spins up an internal app used by my company) and the kafka chart (maintined by Bitnami here) have a dependency to Zookeeper.
Because of this, both charts in their own right spin up Zookeeper by having a dependency within their respective charts, as such:
kafka/requirements.yaml and internaldep/requirements.yaml
dependencies:
- name: zookeeper
version: 5.1.X
repository: https://charts.bitnami.com
condition: zookeeper.enabled
In order avoid spinning up two Zookeeper installations, I opted to just spin up one Zookeeper, and use that one instance for both apps as such:
myapp/requirements.yaml
dependencies:
- name: internaldep
condition: internaldep.enabled
repository: file://../internaldep
version: 0.1.0
- name: kafka
condition: kafka.enabled
repository: https://charts.bitnami.com
version: 6.1.6
+ - name: zookeeper
+ version: 5.1.X
+ repository: https://charts.bitnami.com
+ condition: zookeeper.enabled
I've run into a problem. The kafka chart determines the Zookeeper servers to use based on the following code block:
- name: KAFKA_CFG_ZOOKEEPER_CONNECT
{{- if .Values.zookeeper.enabled }}
value: {{ template "kafka.zookeeper.fullname" . }}
{{- else }}
value: {{ .Values.externalZookeeper.servers | quote }}
{{- end }}
Since I'm setting .Values.zookeeper.enabled
to false
(because I only want to use one Zookeeper installation for both apps), this means I must pass in the DNS names where Zookeeper can be found via .Values.externalZookeeper.servers
.
However, when I try to do this in the values.yaml file:
kafka:
externalZookeeper:
servers: {{ .Release.Name }}-kafka-headless
I receive the error:
error converting YAML to JSON: yaml: line 82: did not find expected key
Is there a smarter way to do this?
Solution 1:[1]
I would recommend deploying multiple helm releases and linking them together with their values. Using helm dependencies you run into issues like this. I would generally not recommend relying on the dependency/requirement feature of helm for anything but but simple test installations. For production environments it's IMO way better to decouple your your application into multiple helm releases, which you can deploy and even switch out independently.
And to answer your question: to my knowledge there is no good way of doing what you want.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Benjamin Hammer Nørgaard |