<p>I'm trying to write a script that runs some commands inside the container using kubectl exec. I'd like to use the environment variables that exist inside the container, but struggling to figure out how to prevent my local shell from evaluating the var and still have it evaluated in the container.</p>

<p>This was my first try, but $MONGODB_ROOT_PASSWORD get evaluated by my local shell instead of inside the container:</p>

<pre><code>kubectl -n enterprise exec mycontainer -- mongodump --username root --password $MONGODB_ROOT_PASSWORD --out /dump
</code></pre>

<p>I tried this, but the had the same issue with pipe, it was evaluated in my local instead of in the container:</p>

<pre><code>kubectl -n enterprise exec mycontainer -- echo 'mongodump --username root --password $MONGODB_ROOT_PASSWORD --out /dump' | sh
</code></pre>

<p>Is there a way to do this with kubectl exec?</p>

<p>You need a <code>sh -c</code> in there, like <code>exec -- sh -c 'whatever $PASSWORD'</code>.</p>
