<p>I need to update a file in a container running in k8s using my local editor and save back the updates to the original file in the container <em>without</em> restarting/redeploying the container.</p>
<p>Right now I do:</p>
<pre><code>$ kubectl exec tmp-shell -- cat /root/motd &gt; motd &amp;&amp; vi motd &amp;&amp; kubectl cp motd tmp-shell:/root/motd
</code></pre>
<p>Is there some better way to do this?</p>
<p>I have looked at:</p>
<p><a href="https://github.com/ksync/ksync" rel="nofollow noreferrer">https://github.com/ksync/ksync</a></p>
<p>but seems heavyweight for something this &quot;simple&quot;.</p>
<p><strong>Notice:</strong></p>
<p>I don't want to use the editor that might or might <em>not</em> be available inside the container - since an editor is not guaranteed to be available.</p>

<p>One option that might be available is <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/debug-running-pod/#ephemeral-container" rel="nofollow noreferrer">ephemeral debug containers</a> however they are an alpha feature so probably not enabled for you at time of writing. Barring that, yeah what you said is an option. It probably goes without saying but this is a very bad idea, might not work at all if the target file isn't writable (which it shouldn't be in most cases) either because of file permissions, or because the container is running in immutable mode. Also this would only matter if the thing using the file will detect the change without reloading.</p>
<p>A better medium term plan would be to store the content in the ConfgMap and mount it into place. That would let you update it whenever you want.</p>
