<p>I want to set some proxy (http, https etc) config on my k8s container. That k8s container will run some user scripts, it may also run some <code>sudo</code> commands in that script.</p>
<p>What is the best way to pass this proxy config in my k8s container.</p>
<p>One approach I was trying was passing the proxy config as env variable to the container in my deployment manifest file.</p>
<p>Drawback: It will set only for default user and not root user. <code>sudo</code> commands will fail. User/container start script will need to set proxy config in the container for root user.</p>
<p>Any other alternative or clean way of passing env variable to all users in the container?</p>
<hr />
<p>Another approach I am using now is <code>env_keep</code> and adding proxy config env variable list in <code>env_keep</code> and when command is executed with sudo in pod, it will take env variable of default user that I set using deployment manifest.</p>
<hr />
<p>Is there any other alternatives ?</p>

<p>Best practice is to run the <code>Init container</code> as <strong>Root</strong>.</p>
<p>And further, once you startup script is done with work you can run your container as the Non-root user.</p>
<p>Init container : <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/init-containers/</a></p>
<p><strong>Update:</strong></p>
<p>You can also use the <code>sudo -E</code></p>
<pre><code>-E, --preserve-env
             Indicates to the security policy that the user wishes to preserve their
             existing environment variables.  The security policy may return an error
             if the user does not have permission to preserve the environment.
</code></pre>
