<p>Does anyone know why this one doesn't (shows empty line):</p>

<pre><code>kubectl exec kube -- echo $KUBERNETES_SERVICE_HOST
</code></pre>

<p>but this one works?</p>

<pre><code>kubectl exec kube -- sh -c 'echo $KUBERNETES_SERVICE_HOST'
</code></pre>

Kim
<p>Running successfully will depend on the image that you are using for <code>kube</code>. But in general terms <code>echo</code> is a built-in <a href="https://en.wikipedia.org/wiki/Bourne_shell" rel="noreferrer">Bourne shell</a> command.  </p>

<p>With this command:</p>

<pre><code>$ kubectl exec kube -- echo $KUBERNETES_SERVICE_HOST
</code></pre>

<p>You are not instantiating a Bourne Shell environment and there is not an <code>echo</code> executable in the container. It turns out what <code>kubectl</code> does is basically running <code>echo $KUBERNETES_SERVICE_HOST</code> on your client! You can try running for example:</p>

<pre><code>$ kubectl exec kube -- echo $PWD
</code></pre>

<p>You'll see that is the home directory on your client.</p>

<p>Whereas with this command:</p>

<pre><code>$ kubectl exec kube -- sh -c 'echo $KUBERNETES_SERVICE_HOST'
</code></pre>

<p>There is a <code>sh</code> executable in your environment and that's Bourne Shell that understands the built-in <code>echo</code> command with the given Kubernetes environment in the default container of your Pod.</p>
