<p>I have a deployment with 2 containers running in the same Pod in my Kubernetes cluster. One is NGINX and the other is a sidecar (bash image). Following is the definition file :-</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      run: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: nginx
    spec:
      volumes:
      - name: logs
        emptyDir: {}
      containers:
      - image: nginx
        name: nginx
        resources: {}
        volumeMounts:
          - name: logs
            mountPath: /var/log/nginx
      - image: bash
        name: sidecar
        command: [&quot;/bin/sh&quot;,&quot;-c&quot;,&quot;tail -f /var/log/sidecar/access.log&quot;]
        volumeMounts:
        - name: logs
          mountPath: /var/log/sidecar
</code></pre>
<p>I understand that the Docker image (NGINX) generates the standard logs to the location <code>/var/log/nginx/access.log</code> (ref-&gt; <a href="https://docs.docker.com/config/containers/logging/" rel="nofollow noreferrer">https://docs.docker.com/config/containers/logging/</a>)</p>
<p>I'm using emptyDir volume which means all the containers will share the same storage location within the pod on the host machine.</p>
<p>When I do curl on the service or Nginx pod, I get successful response from the NGINX server, and its logs can be seen using the <code>kubectl logs &lt;pod name&gt; sidecar -f</code> command on the console.</p>
<p>What I do not understand completely is that the file path in the command (inside bash/sidecar container) is <strong>/var/log/sidecar/access.log</strong> and not /var/log/nginx/access.log then how come I'm able to get those logs because the file access.log does not exists inside the directory /var/log/sidecar.</p>
<p>Please advise, thanks</p>

vinod827
<p>Before getting into your question, you will need to know how Kubernetes Pod works.</p>
<p>In Kubernetes, All the containers in the same Pod are scheduled in the same node. Inside the node, they are orchestrated with the container runtime.</p>
<p>Taking the docker runtime for simplicity, Kubernetes will spawn up two containers according to your configuration. One is the NGINX and one is the bash. In container orchestration, you can define a volume and share them across different container runtime. But behind the scene, they are using the same folders/files from the host machine.</p>
<p>So, circling back to your question, Kubernetes here created two containers in your hosting machine. And it also created a docker volume to share across these two containers. Inside the containers, the volume are mounted into different path but still share the same source of truth, which comes from the worker machine.</p>
<p>In case you want to know how it is going on your worker machine, you can ssh into your worker and run the following command.</p>
<pre><code># Get your container ID
&gt; docker ps
# Inspect your container
&gt; docker inspect &lt;container&gt;
</code></pre>
<p>And try to spot the volume part in the output. You should be able to see that they are sharing the volume.</p>
