<p>This deployment creates 1 pod that has init container in it. The container mounts volume into tmp/web-content and writes 1 single line 'check this out' to index.html</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-init-container
  namespace: mars
spec:
  replicas: 1
  selector:
    matchLabels:
      id: test-init-container
  template:
    metadata:
      labels:
        id: test-init-container
    spec:
      volumes:
      - name: web-content
        emptyDir: {}
      initContainers:
      - name: init-con
        image: busybox:1.31.0
        command: ['sh', '-c' ,&quot;echo 'check this out' &gt; /tmp/web-content/index.html&quot;]
        volumeMounts:
        - name: web-content
          mountPath: /tmp/web-content/
      containers:
      - image: nginx:1.17.3-alpine
        name: nginx
        volumeMounts:
        - name: web-content
          mountPath: /usr/share/nginx/html
        ports:
        - containerPort: 80
</code></pre>
<p>I fire up temporary pod to check if i can see this line 'check this out' using curl.</p>
<pre><code>k run tmp --restart=Never --rm -i --image=nginx:alpine -- curl 10.0.0.67
</code></pre>
<p>It does show the line. However, how does curl know which directory to go in?
I dont specify it should go to /tmp/web-content explicitly</p>

<p>Its because of the <code>mountPath</code>:</p>
<blockquote>
<p>The root directive indicates the actual path on your hard drive where
this virtual host's assets (HTML, images, CSS, and so on) are located,
ie /usr/share/nginx/html. The index setting tells Nginx what file or
files to serve when it's asked to display a directory</p>
</blockquote>
<p>When you curl to default port 80, curl serve you back content of the html directory.
.</p>
