Home > Blockchain >  Is there a way to specify which values file to use in a helm chart
Is there a way to specify which values file to use in a helm chart

Time:03-16

In one of our helm charts we have a values file per environment e.g.

app-helm-chart:
  dev-values.yaml
  test-values.yaml
  Chart.yaml
  templates
    deployment.yaml
    service.yaml
    ingress.yaml
  Readme.md

We have packaged up the helm chart using helm package and are then trying to install it from our helm repository.

Is there a way to specify to use the dev-values file from within the package as part of the install command?

Trying to package and version the values and templates all in one place if possible.

Thanks

CodePudding user response:

Yes.

helm install -f dev-values.yaml ./mychart

https://helm.sh/docs/chart_template_guide/values_files/

CodePudding user response:

There are two answers to this question.

First one, using your current package and repo setup, you would need to download and extract the package then call the values file from the chart folder

helm repo add test-repo http://url/to/your repo
helm repo update
helm fetch test-repo/my-chart-name untar [--version x.x.x]  #This creates a directory called "my-chart-name" in the local directory
helm upgrade --install --atomic --wait ./my-chart-name/ -f ./mychart-name/dev-values.yaml

The second, better way, and this was already hinted to by Gaël J is not to include environment-specific values in the chart -- because if you do, each time you change the values or add new values, you'll need to repackage the chart and update the chart repo.

The better way, and the way we do it is to have a separate folder, something like this

.
├── charts
│   └── my-chart
│       ├── Chart.lock
│       ├── charts
│       │   └── ingress-nginx-3.35.0.tgz
│       ├── Chart.yaml
│       ├── README.md
│       └── templates
│           ├── deployment.yaml
│           ├── _helpers.tpl
│           ├── ingress.yaml
│           ├── NOTES.txt
│           ├── serviceaccount.yaml
│           └── service.yaml
├── profiles
│   ├── values-preprod.yaml
│   └── values-prod.yaml

In this way, I can update the profiles yaml freely and then use the local (or remote) chart -- and the chart contents or version don't need to change whenever I update the values.

helm upgrade --install --atomic --wait ./charts/my-chart -f profiles/values-preprod.yaml

or

helm upgrade --install --atomic --wait test-repo/my-chart -f profiles/values-preprod.yaml
  • Related