<p>My pod has two containers - a primary container, and a sidecar container that monitors the <code>/var/run/utmp</code> file in the primary container and takes action when it changes. I'm trying to figure out how to make this file visible in the sidecar container.</p>

<p><a href="https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/" rel="nofollow noreferrer">This page</a> describes how to use an <code>emptyDir</code> volume to share directories between containers in a pod. However, this only seems to work for directories, not single files. I also can't use this strategy to share the entire <code>/var/run/</code> directory in the primary container, since mounting a volume there erases the contents of the directory, which the container needs to run.</p>

<p>I tried to work around this by creating a symlink to <code>utmp</code> in another directory and mounting that directory, but it doesn't look like symlinks in volumes are resolved in the way they would need to be for this to work.</p>

<p>Is there any way I can make one file in a container visible to other containers in the same pod? The manifest I'm experimenting with looks like this:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: utmp-demo

spec:
  restartPolicy: Never

  containers:
  - name: main
    image: debian
    command: ["/bin/bash"]
    args: ["-c", "sleep infinity"]
    volumeMounts:
    - name: main-run
      mountPath: /var/run  # or /var/run/utmp, which crashes

  - name: helper
    image: debian
    command: ["/bin/bash"]
    args: ["-c", "sleep infinity"]
    volumeMounts:
    - name: main-run
      mountPath: /tmp/main-run

  volumes:
  - name: main-run
    emptyDir: {}
</code></pre>

<p>If you can move the file to be shared in an empty subfolder this could be a simple solution.</p>

<p>For example, move your file to /var/run/utmp/utmp and share /var/run/utmp folder with an emptydir.</p>
