<p>I have php application with <code>public</code> folder, that contains as <code>index.php</code> that handles php requests as static files.</p>

<p>I would like to deliver static files via nginx container directly, and use php-fpm only for delivering dynamic requests.</p>

<p>How that can be achieved? As i understand, there are two ways: </p>

<ol>
<li>create two separate containers with same application folder: the first will be with nginx, that serves static and delegates dynamic requests to the second, where php-fpm would be located.</li>
<li>Second solution is to use <code>persistentVolumeClaim</code>, but that also requires some kind of magic for synchronization (<code>initContainers</code>).</li>
</ol>

<p>What is the best practice?</p>

<p>Let's begin by saying that there are 2 pods which are Nginx Pod and Php pod. 
Now There are two things need to be associated with these pods.</p>

<ul>
<li>Static files (Public folder)</li>
<li>Configuration file (nginx.conf)</li>
</ul>

<p>I would prefer to use Persistent Volume claim for static files and ConfigMap for the configuration file. </p>

<p>Solutions to your issue. </p>

<p>Php pod will have following k8s resources</p>

<ul>
<li>Deployment( containers )</li>
<li>Service (to expose it internal)</li>
<li>PersistentVolumeClaim (for public folder) </li>
<li>ConfigMap ( Environment Variable such as information about database )</li>
</ul>

<p>Nginx pod will have following k8s resources </p>

<ul>
<li>Deployment (Container)</li>
<li>Service (to expose it internal or external)</li>
<li>ConfigMap (customised nginx.conf)</li>
</ul>

<p>Now Deployment Resouces will have a relationship with other resources such as Persistent volume claim and configmap etc.</p>

<p>As I understand by InitContainer, It helps Pod to have a consistent Network Namespace as well as organise file system for the main container it provides all the necessary resources to the main container such as service account, pvc, configmap.</p>

<p>For example, If the main container restart then init container make sure that IP address does not change.However, if you create pod again it means you are creating initcontainer  again then Pod will have new IP address.   </p>
