<p>To display some environment variables in a pod on Kubernetes, I tried it in two ways.</p>
<p>(1) Connecting inside a pod</p>
<p>I connected to shell in a pod and I executed 'echo' command like below..</p>
<pre><code>kubectl exec -it &lt;pod-name&gt; /bin/bash

then...

echo $KUBERNETES_SERVICE_HOST 

</code></pre>
<p>I saw correct result as I expected.</p>
<p>(2) Send a command to a pod</p>
<pre><code>kubectl exec &lt;pod-name&gt; -- echo $KUBERNETES_SERVICE_HOST
</code></pre>
<p>In this case, there is no output.</p>
<p>you can see the screenshot what I did.
<a href="https://i.stack.imgur.com/xsV69.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xsV69.png" alt="enter image description here" /></a></p>
<p>What is the problem here?
What is difference between two situations?</p>
<p>Thanks you :)</p>

<p>In the second case, '$' DOllar in the command references to your local host envrionment variables. And there is no such variable KUBERNETES_SERVICE_HOST on local host, the command that goes looks like below</p>
<p>kubectl exec  -- echo </p>
<p>use below instead</p>
<p>kubectl exec c-hub-admin-app-systest-6dc46bb776-tvb99 -- printenv | grep KUBERNETES_SERVICE_HOST</p>
<p><a href="https://i.stack.imgur.com/o3bFd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o3bFd.png" alt="enter image description here" /></a></p>
