Helm overriding child chart values from parent chart - mongodb

I am new to Helm and using Helm 3. I am trying to build a simple helm chart which depends on the mongodb helm chart available from bitnami here.
This is the structure of my chart:
mychart
|- charts\
|- mongodb-8.1.1.tgz
|- Chart.yaml
|- values.yaml
I am trying to override the value of mongodb.rootPassword (and some other properties) through the values.yaml file of the parent chart. However, it does not override the value specified and reverts to the default values from the mongodb chart.
It would be a great help to understand what I am doing wrong and how can I override the value of the child chart from the parent chart.
Here are the contents of my files:
Chart.yaml
apiVersion: v2
name: mychart
appVersion: "1.0"
description: mychart has the best description
version: 0.1.0
type: application
dependencies:
- name: mongodb
version: 8.1.1
repository: https://charts.bitnami.com/bitnami
condition: mongodb.enabled
values.yaml
mongodb:
global:
namespaceOverride: production
fullnameOverride: mongo-mychart
useStatefulSet: true
auth:
rootPassword: example
persistence:
size: 100Mi

This is possible in case the format of the values.yaml file has an issue. In this case, the values.yaml file of the parent chart had a few extra encoded characters which were causing it to be ignored by helm and defaulting the child chart's values.

Related

Multiple deployments using one helm chart and chart dependencies with alias

I have 10 Deployments that are currently managed by 10 unique helm releases.
But these deployments are so similar that I wish to group them together and manage it as one helm release.
All deployments use the same helm chart, the only difference is in the environment variables passed to the deployment pod which is set in values.yaml.
Can I do this using helm chart dependencies and the alias field?
dependencies:
- name: subchart
repository: http://localhost:10191
version: 0.1.0
alias: deploy-1
- name: subchart
repository: http://localhost:10191
version: 0.1.0
alias: deploy-2
- name: subchart
repository: http://localhost:10191
version: 0.1.0
alias: deploy-3
I can now set values for individual deploys in one parent Chart's values.yaml:
deploy-1:
environment:
key: value-1
deploy-2:
environment:
key: value-2
deploy-3:
environment:
key: value-3
But 99% of the values that I need to set for all the deployments are the same.
How do I avoid duplicating them across the deploy-n keys in the parent chart's values.yaml file?
If you have 10 deployments that are similar, but have only a few differences in environment variables, you can group them together and manage them as one helm release using a single values.yaml file. Here's how you can achieve this:
Define a single dependency in your parent chart's Chart.yaml file that points to the helm chart for your deployments:
dependencies:
- name: my-deployments
version: 1.0.0
repository: https://charts.example.com
Create a single values.yaml file in your parent chart's templates directory that defines the values for your deployments:
my-deployments:
environment:
key1: value1
key2: value2
key3: value3
In your deployment manifests, replace any environment variable values that vary between deployments with references to the values in the parent chart's values.yaml file:
env:
- name: ENV_VAR_1
value: {{ .Values.my-deployments.environment.key1 }}
- name: ENV_VAR_2
value: {{ .Values.my-deployments.environment.key2 }}
- name: ENV_VAR_3
value: {{ .Values.my-deployments.environment.key3 }}
This way, you only need to define the environment variable values that vary between deployments in the parent chart's values.yaml file, and Helm will automatically apply these values to all the deployments.
Note that this approach assumes that all of your deployments use the same Helm chart with the same structure for their deployment manifests. If this is not the case, you may need to adjust the approach accordingly to fit the specific needs of your deployments.

helm template is not using values.yaml file

I can't seem to figure out whey my nginx template is not using the values file when I pass it with the helm template --debug nginx charts/transport-latency -f charts/transport-latency/values.yaml > .ignore/nginx-out.yaml command.
Output using --debug
install.go:178: [debug] Original chart version: ""
install.go:195: [debug] CHART PATH: /Users/<userName>/src/Repos/helm_charts/charts/transport-latency
Here is the structure of the chart:
charts/transport-latency
├── Chart.lock
├── Chart.yaml
├── charts
│ └── nginx-13.1.0.tgz
├── templates
└── values.yaml
And when I run the above mentioned command I just get the default chart without any modification that should be included in the values.yaml file.
Here is what my values.yaml file looks like:
namespaceOverride: airflow
replicaCount: 2
service:
type: ClusterIP
If it helps here is my Chart.yaml contents:
apiVersion: v2
name: transport-latency
type: application
version: 1.0.0
appVersion: "1.0.0"
dependencies:
- name: nginx
version: 13.1.0
repository: https://charts.bitnami.com/bitnami
If you are referencing a dependent chart (in your case, the nginx chart), then you must nest values for that subchart in its own block with the name of the dependency.
So, since you named the dependency nginx as per your chart.yaml:
apiVersion: v2
name: transport-latency
type: application
version: 1.0.0
appVersion: "1.0.0"
dependencies:
- name: nginx
version: 13.1.0
repository: https://charts.bitnami.com/bitnami
You must therefore nest the values for that chart in a block labelled nginx
values.yaml
nginx:
namespaceOverride: airflow
replicaCount: 2
service:
type: ClusterIP
Using your values.yaml as it is:
namespaceOverride: airflow
replicaCount: 2
service:
type: ClusterIP
Would only provide those to your "root" chart -- which is empty.

Helm dependency is false but subchart is deployed anyway

I have a Helm/Kubernetes deployment with the following structure:
mainchart
|- subchart1
| |- database
|- subchart2
...
So, database is a subchart of subchart1; no other subchart contains database.
In subchart1, Chart.yaml says:
dependencies:
- name: database
version: "*"
condition: global.owndb
and Values.yaml says:
global:
owndb: false
Also, in mainchart, Values.yaml says:
global:
owndb: false
When I run "helm install", I supposed the database chart was not deployed. It gets deployed all the times, instead.
Any idea of why it's behaving like this? I'm using helm v3.6.3

How to override values.yaml from parent chart in Helm

I am trying to install rabbitmq helm chart in dependencies section of my parent chart.
Here is my parent chart
apiVersion: v2
name: mychart
description: A Helm chart to install rabbitmq
type: application
version: 1.0.0
appVersion: "1.0.0"
dependencies:
- name: rabbitmq
repository: https://charts.bitnami.com/bitnami
version: 8.11.9
condition: rabbitmq.enabled
And here is the values.yml file of this chart
rabbitmq:
enabled: true
auth.username: test
auth.password: test
I am trying to override the values of auth.username and auth.password of rabbitmq dependency chart. But values are getting override. And default values are used when I deploy/test this chart.
What am I doing wrong here ?
While the helm install --set option takes options like --set rabbitmq.auth.username=..., and charts' documentation generally uses this syntax, in YAML files you need to put each part in a nested block:
rabbitmq:
enabled: true
auth:
# "username" under "auth", not a single key "auth.username"
username: test
password: test

kubernetes helm: How to set env variable of child chart in parent chart

We are using helm to deploy many charts, but for simplicity let's say it is two charts. A parent chart and a child chart:
helm/parent
helm/child
The parent chart has a helm/parent/requirements.yaml file which specifies:
dependencies:
- name: child
repository: file://../child
version: 0.1.0
The child chart requires a bunch of environment variables on startup for configuration, for example in helm/child/templates/deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
spec:
replicas: 1
strategy:
type: Recreate
template:
spec:
containers:
env:
- name: A_URL
value: http://localhost:8080
What's the best way to override the child's environment variable from the parent chart, so that I can run the parent using below command and set the A_URL env variable for this instance to e.g. https://www.mywebsite.com?
helm install parent --name parent-release --namespace sample-namespace
I tried adding the variable to the parent's helm/parent/values.yaml file, but to no avail
global:
repository: my_repo
tag: 1.0.0-SNAPSHOT
child:
env:
- name: A_URL
value: https://www.mywebsite.com
Is the syntax of the parent's value.yaml correct? Is there a different approach?
In the child chart you have to explicitly reference a value from the configuration. (Having made this change you probably need to run helm dependency update from the parent chart directory.)
# child/templates/deployment.yaml, in the pod spec
env:
- name: A_URL
value: {{ .Values.aUrl | quote }}
You can give it a default value for the child chart.
# child/values.yaml
aUrl: "http://localhost:8080"
Then in the parent chart's values file, you can provide an override value for that.
# parent/values.yaml
child:
aUrl: "http://elsewhere"
You can't use Helm to override or inject arbitrary YAML, except to the extent the templates allow for it.
Unless the value is set up using the templating system, there is no way to directly modify it in Helm 2.