<p>I am trying to learn Kubernetes. I was going through a link but not able to understand one thing.</p>
<p>URL: <a href="https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/</a></p>
<p>Mentioned in the doc:</p>
<blockquote>
<p>Notice that the second container writes the index.html file in the root directory of the nginx server.</p>
</blockquote>
<p>How is this HTML file created in the root directory of the Nginx server? As we are executing this command in the different container i.e. debian-container.</p>

KiddoDeveloper
<p>In the example from the link you posted you have:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: two-containers
spec:

  restartPolicy: Never

  volumes:
  - name: shared-data
    emptyDir: {}

  containers:

  - name: nginx-container
    image: nginx
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/nginx/html

  - name: debian-container
    image: debian
    volumeMounts:
    - name: shared-data
      mountPath: /pod-data
    command: [&quot;/bin/sh&quot;]
    args: [&quot;-c&quot;, &quot;echo Hello from the debian container &gt; /pod-data/index.html&quot;]
</code></pre>
<p>You have two containers which share a volume, named <code>shared-data</code>. Each container decides where does it want to mount the volume:</p>
<ul>
<li><code>nginx-container</code> is mounting it to <code>/usr/share/nginx/html</code> (also known as Nginx's default root directory)</li>
<li><code>debian-container</code> is mounting it to <code>/pod-data</code>.</li>
</ul>
<p>Since shared volume is like a shared directory on a computer or in a cloud, everything present in the volume is available in both containers under the <code>mountPath</code> path.</p>
<p>In the example, the <code>debian-container</code> writes <code>index.html</code> file to a shared space, which can then be used by <code>nginx-container</code>.</p>
<p>This is a well-known pattern in Kubernetes, called Sidecar Container Pattern. In this case <code>debian-container</code> is a sidecar container. It extends and enhances the functionality of main container (<code>nginx-container</code>) - provides <code>index.html</code> file in this simple example.</p>
<hr />
<p>Resources:</p>
<ul>
<li><a href="https://medium.com/bb-tutorials-and-thoughts/kubernetes-learn-sidecar-container-pattern-6d8c21f873d" rel="nofollow noreferrer">Kubernetes — Learn Sidecar Container Pattern</a></li>
<li><a href="https://www.magalix.com/blog/the-sidecar-pattern" rel="nofollow noreferrer">The Sidecar Pattern</a></li>
</ul>
