1

I am trying to make an helm chart for my custom elk stack. I use the stable/elasticsearch-curator chart as a dependency.

In my values.yaml file, I use some env variables to pass the elasticsearch host:

esClusterName: &esClusterName "elasticsearch-logs"

...

elasticsearch-curator:

  env:
    ES_CLUSTER_NAME: *esClusterName
    ELASTICSEARCH_HOST: $(ES_CLUSTER_NAME)-master

  configMaps:

    config_yml: |-
      ---
      client:
        hosts:
          - ${ELASTICSEARCH_HOST}
        port: 9200

But the variable is not correctly interpolated as shown by this error message:

HTTP N/A error: HTTPConnectionPool(host='$(es_cluster_name)-master', port=9200): Max retries exceeded with ...

Inside my pod, ELASTICSEARCH_HOST = '$(es_cluster_name)-master' --a string of the name of my variable in LOWERCASE and "-master"-- instead of "elasticsearch-logs-master".

I cannot wrap my head arround this. I have used the same technique -- env variable interpolation -- for the other dependencies and it works.

The only difference I see is that the helm chart for elasticsearch-curator passes env variables differently from the other charts:

# stable/elasticsearch-curator/templates/cronjob.yaml (The file is here)

            env:
{{- if .Values.env }}
{{- range $key,$value := .Values.env }}
              - name: {{ $key | upper | quote}}
                value: {{ $value | quote}}
{{- end }}
{{- end }}

And this template expects the values to be passed in values.yaml like so: ( the file is here)

env:
  MY_ENV_VAR: value1
  MY_OTHER_VAR: value2

whereas all other templates use this way: ( exemple file)

        env: {{ toYaml .Values.extraEnvs | nindent 10 }}

with a values.yaml like so: ( exemple file)

extraEnvs: 
  - name: MY_ENVIRONMENT_VAR
    value: the_value_goes_here

But I'm not sure if this difference explains my problem. So my question is: how do I make it work?

OLIVIER
  • 858
  • 9
  • 18
  • You can't put env variables in `values.yaml`. You must specify them on the helm command line. – Jonathan Hall Nov 27 '19 at 10:30
  • @Flimzy I know, that's why I do not put variables in my values.yaml file. Instead, I use YAML ANCHORS that I pass to an env variable which is interpolated inside another env variable INSIDE MY POD. It works for all my other carts. Just not this one. The reason I do not use the helm command line to pass them is that it is an umbrella chart that has to pass similar values to numerous dependencies. Using the command line would defeat the purpose of this chart. – OLIVIER Nov 27 '19 at 10:47
  • Faced the same issue. Fixed by renaming variables, so if they go alphabetically, k8s may resolve them in the right order. I have ENV=dev and DBHOST=$(ENV)-example-com. After automatically sorting with Helm DBHOST goes first and cant resolve ENV, so I need to rename variable to HOST, for example. Probably there is should be any rule to sort or not envs in helm but I did not find it. – Vadim Yangunaev Jan 22 '21 at 18:44

1 Answers1

3

I replaced ELASTICSEARCH_HOST with ES_HOST like so:

elasticsearch-curator:

  env:
    ES_CLUSTER_NAME: *esClusterName
    ES_HOST: $(ES_CLUSTER_NAME)-master

  configMaps:

    config_yml: |-
      ---
      client:
        hosts:
          - ${ES_HOST}
        port: 9200

and it just worked!

I think it comes from the fact that when values.yaml is parsed, the keys from the env: object are sorted in alphabetical order:

env: {
  ELASTICSEARCH_HOST: $(ES_CLUSTER_NAME)-master
  ES_CLUSTER_NAME: "elasticsearch-logs"
}

Then, when the pod tries to interpolate the value of ES_CLUSTER_NAME inside ELASTICSEARCH_HOST, it does not work since it doesn't know the value of ES_CLUSTER_NAME yet.

It would be nice to have confirmation (or infirmation) of this.

OLIVIER
  • 858
  • 9
  • 18