<p>I am trying to add config data as environment variables, but Kubernetes warns about invalid variable names. The configmap data contains JSON and property files.</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  containers:
    - name: env-var-configmap
      image: nginx:1.7.9 
      envFrom:
        - configMapRef:
            name: example-configmap
</code></pre>
<p>After deploying I do not see them added in the process environment. Instead I see a warning message like below</p>
<blockquote>
<p>Config map example-configmap contains keys that are not valid environment variable names. Only config map keys with valid names will be added as environment variables.</p>
</blockquote>
<p>But I see it works if I add it directly as a key-value pair</p>
<pre class="lang-yaml prettyprint-override"><code>env:
  # Define the environment variable
  - name: SPECIAL_LEVEL_KEY
    valueFrom:
      configMapKeyRef:
        # The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
        name: special-config
        # Specify the key associated with the value
        key: special.how
</code></pre>
<p>I have thousand of key values in the configmap data and I could not add them all as separate key-value pairs.</p>
<p>Is there any short syntax to add all values from a configmap as environment variables?</p>

ramesh reddy
<p>My answer, while @P-Ekambaram already helped you out, I was getting the same error message, it turned out that my issue was that I named the configMap <code>ms-provisioning-broadsoft-adapter</code> and was trying to use <code>ms-provisioning-broadsoft-adapter</code> as the key.  As soon as I changed they key to <code>ms_provisioning_broadsoft_adapter</code>, e.g. I added the underscores instead of hyphens and it happily let me add it to an application.</p>
<p>Hope this might help someone else that also runs into the error <code>invalid variable name cannot be added as environmental variable</code></p>
