<p>I need to define an env var with name contains '.' characters, and Kubenetes does not seem to like it.</p>

<pre><code>    spec:
      containers:
        env:
        - name: "com.my.app.dir"
          value: "/myapp/subdir/"
</code></pre>

<p>I tried single quotes, double quotes, backslashes, double backslashes, and many other ways. Still cannot make it work. I wonder if anyone knows a way to escape the '.' characters. Thanks in advance.</p>

Edwin
<p>Kubernetes doesn't have a problem setting an environment variable with a <code>.</code></p>

<p>Here's a simple spec that logs the environment by directly running the <code>node</code> executable</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: env-node
spec:
  containers:
  - image: 'node:12-slim'
    name: env-node
    command:
    - node
    - '-pe'
    - process.env
    env:
    - name: OTHER
      value: here
    - name: 'ONE_two-Three.four'
      value: 'diditwork'
</code></pre>

<p>And the environment output (with some kubernetes default vars removed for brevity)</p>

<pre><code>{
  PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
  HOSTNAME: 'env-node',
  NODE_VERSION: '12.16.1',
  OTHER: 'here',
  'ONE_two-Three.four': 'diditwork',
  HOME: '/root'
}
</code></pre>

<p>Most shells (<code>sh</code>, <code>bash</code>, <code>zsh</code>) won't accept environment variables with a <code>.</code> in them. POSIX defines <code>[a-zA-Z_][a-zA-Z0-9_]*</code> as the allowed characters in the name of an environment variable.</p>

<p>So running the same node process via a shell:</p>

<pre><code>spec:
  containers:
  - image: 'node:12-slim'
    name: nodeenvtest-simple-shell
    command:
    - sh
    - '-c'
    - 'node -e "console.log(process.env)"'
    env:
    - name: 'ONE_two-Three.four'
      value: 'diditwork'
    - name: 'OTHER'
      value: 'here'
</code></pre>

<p>Results in a missing environment variable:</p>

<pre><code>{
  NODE_VERSION: '12.16.1',
  HOSTNAME: 'env-shell',
  HOME: '/root',
  OTHER: 'here',
  PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
  PWD: '/'
}
</code></pre>

<p>If there is no shell between the container and the app running, a <code>.</code> after the first character in the environment variable should be fine. </p>
