Kubernetes - Helm not upgrading cron job

3/18/2021

I have deployed many things with Helm into my Kubernetes cluster. My values.yaml file contains a lot of fields.

The only modification I want to perform is add an additional environment variable to my cron job. (This cron job creates a pod where a python script should be able to read this environment variable)

apiVersion: batch/v1beta1
kind: CronJob
...
...
    containers:
        - env:
            - name: existing_env_var
              value: "dummy_value"
            - name: new_env_var                # I want to add this one
              value: "this is the new one"

The update must be done keeping the old unmodified values. The command: helm upgrade [name] [path] --reuse-values

The problem is that cron job is not upgraded, meaning my python script can not use the new env variable. Only reason I can think of that no changes were made in the context of helm because none of the values were modified.

How could I upgrade my CronJob while reusing the old values. Any help appreciated.

-- Robert
kubernetes
kubernetes-cronjob
kubernetes-helm
kubernetes-jobs

1 Answer

3/19/2021

This has got to do with the definition of the --reuse-values flag. As per the documentation here:

--reuse-values : when upgrading, reuse the last release's values and merge in any overrides from the command line via --set and -f

Trying overrides directly from within the chart while using --reuse-values would not work. Pass the new value (which is the only value you want to add to this chart) via --set or -f.

This will presumably mean you will have to tweak your chart a bit to pass the environment variables to your cron job via values file.

This article explains its usage very well.

-- rock'n rolla
Source: StackOverflow