<p>I am trying to pass an environment variable in kubernetes container.</p>

<p><strong>What have I done so far ?</strong></p>

<ul>
<li><p>Create a deployment</p>

<p><code>kubectl create deployment foo --image=foo:v1</code></p></li>
<li><p>Create a NODEPORT service and expose the port</p>

<p><code>kubectl expose deployment/foo --type=NodePort --port=9000</code></p></li>
<li><p>See the pods</p>

<p><code>kubectl get pods</code></p></li>
<li><p>dump the configurations (so to add the environment variable)</p>

<p><code>kubectl get deployments -o yaml &gt; dev/deployment.yaml</code></p>

<p><code>kubectl get svc -o yaml &gt; dev/services.yaml</code></p>

<p><code>kubectl get pods -o yaml &gt; dev/pods.yaml</code></p></li>
<li><p>Add env variable to the pods
env:</p>

<ul>
<li>name: FOO_KEY
value: "Hellooooo"</li>
</ul></li>
<li><p>Delete the svc,pods,deployments</p>

<p><code>kubectl delete -f dev/ --recursive</code></p></li>
<li><p>Apply the configuration</p>

<p><code>kubectl apply -f dev/ --recursive</code></p></li>
<li><p>Verify env parameters</p>

<p><code>kubectl describe pods</code></p></li>
</ul>

<p><strong>Something weird</strong></p>

<p>If I manually changed the meta information of the pod yaml and hard code the name of the pod. It gets the env variable. However, this time two pods come up one with the hard coded name and other with the hash with it. For example, if the name I hardcoded was "foo", two pods namely foo and foo-12314faf (example) would appear in "kubectl get pods". Can you explain why ?</p>

<p><strong>Question</strong></p>

<p>Why does the verification step does not show the environment variable ?</p>

<p>As the issue is resolved in the comment section. </p>

<p>If you want to set <strong>env</strong> to pods I would suggust you to use <strong>set</strong> sub commend </p>

<p><code>kubectl set env --help</code>  will provide more detail such as list the env and create new one</p>

<pre><code>Examples:
  # Update deployment 'registry' with a new environment variable
  kubectl set env deployment/registry STORAGE_DIR=/local

  # List the environment variables defined on a deployments 'sample-build'
  kubectl set env deployment/sample-build --list
</code></pre>

<p>Deployment enables declarative updates for Pods and ReplicaSets. Pods are not typically directly launched on a cluster. Instead, pods are usually managed by replicaSet which is managed by deployment. </p>

<p>following thread discuss <a href="https://stackoverflow.com/questions/41325087/what-is-the-difference-between-a-pod-and-a-deployment">what-is-the-difference-between-a-pod-and-a-deployment</a></p>
