title: How can I temporarily change an environment variable of a kubernetes pod?
body: <p>We have python services running in pods in a kubernetes cluster. The services are setup to receive their log-level from an environment variable. Those env vars are set during the deployment of the service in a gitlab pipeline. For debugging purposes I want to be able to just change the env var on a single pod and restart it, without having to redeploy the service from gitlab.</p>
  <p>Before we moved to kubernetes, we were running our containers in rancher, where the described change was very easy to do in the GUI. Change the env var -&gt; hit update -&gt; container restarts automatically.</p>
  <p>I found <a href="https://medium.com/@tszumowski/how-to-inject-environment-variables-into-kubernetes-pods-after-deployment-489306fff1a8" rel="nofollow noreferrer">this article</a> that suggest to change the replica set using a command like</p>
  <pre class="lang-sh prettyprint-override"><code>kubectl set env rs [REPLICASET_NAME] [ENV_VAR]=[VALUE]
  </code></pre>
  <p>And then terminating the pod, after which it will be recreated with the env var set accordingly.</p>
  <p>But it also states to</p>
  <blockquote>
  <p>Never do it on a production system.</p>
  <p>Never even do this on a dev environment without taking care in how it may impact your deployment workflow.</p>
  </blockquote>
  <p>Is that the only / best way to achieve my goal of quickly changing an env var in a running pod for debug purposes?</p>