<p>For example, I run a Pod in a public cloud cluster. The Pod has a main container running the app. The cluster has an environment variable named <code>ABC</code>. Within the main container, I wish to access the environment variable <code>ABC</code>. What is the best way to do so?</p>

<p><strong>Very simple option</strong></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: envar-demo
  labels:
    purpose: demonstrate-envars
spec:
  containers:
  - name: envar-demo-container
    image: gcr.io/google-samples/node-hello:1.0
    env:
    - name: DEMO_GREETING
      value: &quot;Hello from the environment&quot;
    - name: DEMO_FAREWELL
      value: &quot;Such a sweet sorrow&quot;
</code></pre>
<p>Read more : <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/</a></p>
<p><strong>Option 1</strong></p>
<p>If variables is not much important you can use the configmap to store the and config map will get injected to POD and your app can access the variables from OS.</p>
<p>Read more about configmap : <a href="https://kubernetes.io/docs/concepts/configuration/configmap/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/configuration/configmap/</a></p>
<p>Example configmap :</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
  namespace: default
data:
  SPECIAL_LEVEL: very
  SPECIAL_TYPE: charm 
</code></pre>
<p>example pod</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;ls /etc/config/&quot; ]
      volumeMounts:
      - name: config-volume
        mountPath: /etc/config
  volumes:
    - name: config-volume
      configMap:
        # Provide the name of the ConfigMap containing the files you want
        # to add to the container
        name: special-config
  restartPolicy: Never
</code></pre>
<p>You can also inject files with list of variables as per requirement.</p>
<p><strong>Option 2</strong> :</p>
<p>You can also use secret if your variable is important : <a href="https://kubernetes.io/docs/concepts/configuration/secret/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/configuration/secret/</a></p>
<p><strong>Option 3</strong> :</p>
<p>If you want to go with best practices and options you can use the <strong>vault</strong> with Kubernetes for managing all different microservice variables management.</p>
<p>Vault : <a href="https://www.vaultproject.io/" rel="nofollow noreferrer">https://www.vaultproject.io/</a></p>
<p>Example : <a href="https://github.com/travelaudience/kubernetes-vault-example" rel="nofollow noreferrer">https://github.com/travelaudience/kubernetes-vault-example</a></p>
<p>it key-value pair management and provides good security options also.</p>
