<p>I am learning how Kubernetes works, with the objective of migrating a &quot;Virtual Machine&quot; environment to a &quot;Kubernetes Container&quot; environment.<br />
The final objective is to be able to absorb peak loads (auto scaling).</p>
<p><strong>Currently,</strong> we have a PHP web application (Symfony) running on multiple Debian VMs, which we call &quot;Workers&quot;.<br />
Each VM is a &quot;worker&quot;, it owns the PHP source code, NGINX and PHP-FPM.</p>
<p><em>PHP sessions are not a problem because they are stored in a cluster-redis.<br />
The databases is stored in a cloud-provider.<br />
The file storage is also in cloud-provider, S3 protocol.</em></p>
<p><strong>With this environment</strong> when we push code in production, <strong>we do a git pull via Ansible</strong> on all the &quot;workers&quot;, and it works fine, nice !</p>
<p><strong>So now with Kubernetes ;</strong>
I am a little confused to transcribe this operations in Kubernetes, more particularly the &quot;source code&quot; part.<br />
I have already done this;</p>
<ul>
<li>Create PHP-FPM / NGINX services</li>
<li>Create the PHP-FPM / NGINX deployments, with the nginx vhost stored in a configmap.</li>
</ul>
<p>All this is working fine, my PHP / NGINX environment is up and running fine.</p>
<p>Now my biggest problem, how do I get the source code to run in my pods?</p>
<p>I thought about using an init container, which would make a &quot;git clone&quot; of my code when starting the pods, in a /code volume.<br />
However, once the pods are up and running, how can I git pull them, kill them and reinitialize? Poor solution ?</p>
<p>The other idea I have is to do a Kubernetes Jobs, which I run every time it is necessary to pull new code?</p>
<p>Can you advise me ?<br />
<strong>What is the best solution for &quot;git pull&quot; code in running containers?</strong> As I did before with my VMs, via a git pull from Ansible on all VMs.</p>

Dreamsanon
<p>You would not update the code in a container itself. Instead you would build a new image from the code every time you release (or let your CI pipeline do that, assuming you have one). Then in a second step, you would tell kubernetes to recreate the container with the new image you just built.</p>
