Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override a helm value

I am actually working on a development environment using Gradle, Docker, Minikube and Helm.

I am using a bunch of bash scripts to get things done.

What I achieved so far is:

  1. Gradle builds the jar using a plugin for versioning.
  2. Gradle builds a docker image with the same version calculated on the jar job.

Now I need to be able to propagate the version calculated by Gradle to Helm so it can pick the right docker image.

The approach I already have in mind is to define an environment variable so it can be used by Helm.

The problem is that I would need to redefine it afterward.

Is any better way of doing that?

like image 261
Marcos J.C Kichel Avatar asked Mar 11 '18 17:03

Marcos J.C Kichel


People also ask

What is $_ in Helm?

The $_ is used to suppress undesired output as "set" returns the new dictionary. The above returns: - name: mongod-none. Any values added to the dictionary will live beyond the call. If you want to avoid polluting an existing dictionary you can force a deep copy with: {{- $d := merge (dict) . -}}

What does {{- mean in Helm?

{{- (with the dash and space added) indicates that whitespace should be chomped left, while -}} means whitespace to the right should be consumed.

What is Helm values YAML?

All Helm packed applications have an associated values. yaml file which dictates the configuration of an application. By design many applications ship with a default values. yaml file that is tuned for production deployments which quite often impacts the viability of a prototype or trial deployment.


1 Answers

Most Helm charts contain at least the following in their values.yaml file, which sets a default docker image tag, and also allows the user installing/upgrading the chart to specify a different image without having to modify the chart itself.

# values.yaml
image:
  repository: <docker-repo-url-here>
  tag: <docker-image-tag-here>

And in the deployment yaml, fetch the values from the values.yaml

# deployment.yaml
kind: Deployment
spec:
  template:
    spec:
      containers:
      - name: container-name
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag}}"

From there, you can do a simple helm upgrade <release-name> <chart-path> --set image.tag=<new-image-tag> when you want to use a new image.

like image 65
Grant David Bachman Avatar answered Sep 21 '22 08:09

Grant David Bachman