Cannot read the env vars from config map

10/2/2019

I am new to kubectl and I am trying to use config map in one of my pods:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "couchdb.fullname" . }}
  labels:
    app: {{ template "couchdb.name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
data:
  inifile: |
    {{ range $section, $settings := .Values.couchdbConfig -}}
    {{ printf "[%s]" $section }}
    {{ range $key, $value := $settings -}}
    {{ printf "%s = %s" $key ($value | toString) }}
    {{ end }}
    {{ end }}
  resultCouchHosts:  {{ template "couchdb.svcname" . }}

  seedlistinifile: |
    [cluster]
    seedlist = {{ template "couchdb.seedlist" . }}

So as you see I have a resultCouchHosts: {{ template "couchdb.svcname" . }} as the key value map and I try to read it as follows in my pods:

env:
  - name: RESULTS_COUCH_HOST
    valueFrom:
      configMapKeyRef:
        name: {{template "couchdb.fullname" . }}
        key: resultCouchHosts
    #value: 'de-svc-couchdb'

Running above does not do anything and when I run kubectl get pods mypod I do not see it running but the following works like a charm:

    env:
  - name: RESULTS_COUCH_HOST
    value: 'de-svc-couchdb'

Can anyone shed light on this?

-- Learner
configmap
kubernetes
kubernetes-helm
kubernetes-pod

0 Answers