title: Kubectl set environment variables and run command
body: <p>I have a container running on Kubernetes where I would like to run a command from my local terminal. The working directory of the container based on its yaml file is at say <code>/opt/gopath/src/a/</code>. However, I would like to run the command at directory <code>/opt/gopath/src/b/</code>. Additionally, I also need to set certain temporary environment variables before running this command. So currently, this is what I am doing:</p>
  
  <p><code>
  kubectl exec $pod_name -- bash -c "cd ../b/; env ENV_VARIABLE_1=ENV_VALUE_2 &amp;&amp; env ENV_VARIABLE_2=ENV_VALUE_2 &amp;&amp; &lt;cmd to run&gt;".
  </code></p>
  
  <p>This seems to be working currently. However, I am not convinced that this is the best way to achieve this. Also, running this command displays all the environment variables in the container -- which I would like not to be printed if possible. Could anyone point me in the right direction?</p>