<p>I'm hosting some stuff as an AppService in Azure and use environment variables to differentiate settings for different slots (test, dev etc).</p>

<p>If the AppSettings.json file contains a structure like:</p>

<pre><code>{
   "ConnectionString": {
      "MyDb": "SomeConnectionString"
   }
}
</code></pre>

<p>I can set the environment variable "ConnectionString:MyDb" to "SomeConnectionString" and .Net Core will understand that the <code>:</code> means child level.</p>

<p>But in Kubernetes I cannot use <code>:</code> as part of the environment key. Is there another way to handle hierarchy or do I need to switch to flat settings? </p>

Paaland
<p>I believe you are referring to the <code>env</code> in the container definition for a Pod. From the YAML/JSON perspective, I don't see a problem with specifying a <code>:</code> in a key for an environment variable. You can also put it within quotes and should be valid JSON/YAML:</p>

<pre><code># convert.yaml
apiVersion: v1
kind: Pod
metadata:
  name: envar-demo
  labels:
    purpose: demonstrate-envars
spec:
  containers:
  - name: envar-demo-container
    image: dotnetapp
    env:
    - name: ConnectionString:Mydb
      value: ConnectionString
</code></pre>

<p>Same in JSON:</p>

<pre><code>$ kubectl convert -f convert.yaml -o=json
{
    "kind": "Pod",
    "apiVersion": "v1",
    "metadata": {
        "name": "envar-demo",
        "creationTimestamp": null,
        "labels": {
            "purpose": "demonstrate-envars"
        }
    },
    "spec": {
        "containers": [
            {
                "name": "envar-demo-container",
                "image": "dotnetapp",
                "env": [
                    {
                        "name": "ConnectionString:Mydb",
                        "value": "ConnectionString"
                    }
                ],
                "resources": {},
                "terminationMessagePath": "/dev/termination-log",
                "terminationMessagePolicy": "File",
                "imagePullPolicy": "Always"
            }
        ],
        "restartPolicy": "Always",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "ClusterFirst",
        "securityContext": {},
        "schedulerName": "default-scheduler"
    },
    "status": {}
}
</code></pre>

<p>However, looks like this was a known issue with Windows/.NET applications. An attempt to fix it <a href="https://github.com/kubernetes/kubernetes/pull/59599" rel="nofollow noreferrer">has been tried</a> and ditched due to the fact the this is not valid in Bash. But looks like they settled to use the <code>__</code> instead of <code>:</code> <a href="https://github.com/kubernetes/website/pull/7657/files" rel="nofollow noreferrer">workaround</a></p>
