<p>I have two containers within my pod, one container is an app, that write logs (stdout/stderr), and second container is to read the logs of the app container, and to write it logs.txt file.</p>

<p>My question is, how can I tell the second container to read the logs of the app container?</p>

<p>When I'm on the host (with k8s), I can run:</p>

<pre><code> $kubectl logs -f my_pod &gt;&gt; logs.txt
</code></pre>

<p>and get the logs of pod. </p>

<p>But how can I tell one container to read the logs of another container inside same pod?</p>

<p>I did something similar with dockers: 
I mounted the docker.sock of the docker of the host, and did <code>$docker logs -f app_container &gt;&gt; logs.txt</code>
But I can't (as far as I know) mount kubectl to container in pod, to run kubectl commands.</p>

<p>So how do you think I can do it? </p>

Yagel
<p>you could mount a volume on both containers, write a logfile on that volume on your "app" container, then read from that logfile in the other container.</p>

<p>the preferred solution is probably to use some kind of logshipper or sidecar to scrape the logs from stdout</p>

<p>(side note: you should probably never mount docker.sock into a container or try to run kubectl from one inside a container to the cluster, because you essentially give that container control over your cluster, which is a security no-no imho.
if you still have to do that for whatever reason, make sure the cluster security is REALLY tight)</p>
