<p>I am trying to put two nodejs applications into the same pod, because normally they should sit in the same machine, and are unfortunately heavily coupled together in such a way that each of them is looking for the folder of the other (pos/app.js needs /pos-service, and pos-service/app.js needs /pos)</p>
<p>In the end, the folder is supposed to contain:</p>
<pre><code>/pos 
/pos-service
</code></pre>
<p>Their volume doesn't need to be persistent, so I tried sharing their volumes with an emptyDir like the following:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: pos-deployment
  labels:
    app: pos
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pos
  template:
    metadata:
      labels:
        app: pos
    spec:
      volumes:
      - name: shared-data
        emptyDir: {}
      containers:
      - name: pos-service
        image: pos-service:0.0.1
        volumeMounts:
        - name: shared-data
          mountPath: /pos-service
      - name: pos
        image: pos:0.0.3
        volumeMounts:
        - name: shared-data
          mountPath: /pos
</code></pre>
<p>However, when the pod is launched, and I exec into each of the containers, they still seem to be isolated and eachother's folders can't be seen</p>
<p>I would appereciate any help, thanks</p>

<p><em>This is a Community Wiki answer so feel free to edit it and add any additional details you consider important.</em></p>
<p>Since this issue has already been solved or rather clarified as in fact there is nothing to be solved here, let's post a <strong>Community Wiki</strong> answer as it's partially based on comments of a few different users.</p>
<p>As <a href="https://stackoverflow.com/users/1318694/matt">Matt</a> and <a href="https://stackoverflow.com/users/10008173/david-maze">David Maze</a> have already mentioned, it works as expected and in your example there is nothing that copies any content to your <code>emptyDir</code> volume:</p>
<blockquote>
<p>With just the YAML you've shown, nothing ever copies anything into the
emptyDir volume, unless the images' startup knows to do that. – David
Maze Dec 28 '20 at 12:45</p>
</blockquote>
<p>And as the name itselt may suggest, <a href="https://kubernetes.io/docs/concepts/storage/volumes/#emptydir" rel="nofollow noreferrer"><code>emptyDir</code></a> comes totally empty, so it's your task to pre-populate it with the desired data. It can be done with the <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">init container</a> by temporarily mounting your <code>emptyDir</code> to a different mount point e.g. <code>/mnt/my-epmty-dir</code> and copying the content of specific directory or directories already present in your container e.g. <code>/pos</code> and <code>/pos-service</code> as in your example and then mounting it again to the desired location. Take a look at <a href="https://stackoverflow.com/a/63286102/11714114">this example</a>, presented in one of my older answers as it can be done in the very same way. Your <code>Deployment</code> may look as follows:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: pos-deployment
  labels:
    app: pos
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pos
  template:
    metadata:
      labels:
        app: pos
    spec:
      volumes:
      - name: shared-data
        emptyDir: {}
      initContainers:
      - name: pre-populate-empty-dir-1
        image: pos-service:0.0.1
        command: ['sh', '-c', 'cp -a /pos-service/* /mnt/empty-dir-content/']
        volumeMounts:
         - name: shared-data
           mountPath: &quot;/mnt/empty-dir-content/&quot;
      - name: pre-populate-empty-dir-2
        image: pos:0.0.3
        command: ['sh', '-c', 'cp -a /pos/* /mnt/empty-dir-content/']
        volumeMounts:
         - name: shared-data
           mountPath: &quot;/mnt/empty-dir-content/&quot;
      containers:
      - name: pos-service
        image: pos-service:0.0.1
        volumeMounts:
        - name: shared-data
          mountPath: /pos-service
      - name: pos
        image: pos:0.0.3
        volumeMounts:
        - name: shared-data
          mountPath: /pos
</code></pre>
<p>It's worth mentioning that there is nothing surprising here as it is exacly how <code>mount</code> works on <strong>Linux</strong> or other <strong>nix-based</strong> operating systems.</p>
<p>If you have e.g. <code>/var/log/your-app</code> on your main disk, populated with logs and then you mount a new, empty disk defining as its mountpoint <code>/var/log/your-app</code>, you won't see any content there. It won't be deleted from its original location on your main disc, it will simply become unavailable as in this location now you've mounted completely different volume (which happens to be empty or may have totally different content). When you unmount and visit your <code>/var/log/your-app</code> again, you'll see its original content. I hope it's all clear.</p>
