<p>I am using helm right now. My project is like that:</p>

<p><strong>values.yaml:</strong></p>

<pre><code>environmentVariables:
  KEY1: VALUE1
  KEY2: VALUE2
</code></pre>

<p><strong>configmap.yaml:</strong></p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "myproject.fullname" . }}
data:
{{- range $k, $v := .Values.environmentVariables }}
  {{ $k }}: {{ $v | quote }}
{{- end }}
</code></pre>

<p><strong>deployment.yaml:</strong></p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "myproject.fullname" . }}
spec:
  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
{{- range $k, $v := .Values.environmentVariables }}
            - name: {{ $k }}
              valueFrom:
                configMapKeyRef:
                  name: {{ template "myproject.fullname" $ }}
                  key: {{ $k }}
{{- end }}
...
</code></pre>

<p>But right now, I'm really confused. Am I really need this configmap? Is there any benefit to use configmap for environment variables?</p>

yozel
<p>Aside from the points about separation of config from pods, one advantage of a ConfigMap is it lets you make the values of the variables accessible to other Pods or apps that are not necessarily part of your chart. </p>

<p>It does add a little extra complexity though and there can be a large element of preference about when to use a ConfigMap. Since your ConfigMap keys are the names of the environment variables <a href="https://gist.github.com/troyharvey/4506472732157221e04c6b15e3b3f094" rel="noreferrer">you could simplify your Deployment a little by using 'envFrom'</a></p>
