<p>My pod have more than one log file, such as <code>php-fpm</code> + <code>nginx</code> stack. How to collect the log files?</p>

<p>I know nginx doing it with symlink. But this cannot deal with more than 2 log files.</p>

<p>I want to mount volume in host to pods, but how to set different folder for every pod? Is there anyway to mount a folder named by <code>podname</code> in the host to pod folder <code>/logs</code>.</p>

<p><a href="https://github.com/raychaser/powerstrip-logfiles" rel="nofollow noreferrer">raychaser</a> gave a way to collect folders to <code>/var/log/containers/</code>, but I don't think it works in kubernetes.</p>

<p>Finally, I find a way to collect the logs. </p>

<ol>
<li>Make sure all apps write all log files to a folder, e.g.
<code>/med/log</code>.</li>
<li>Make sure all apps start the job with a script, e.g.
<code>entrypoint.sh</code>.</li>
<li>Create a folder named by $HOSTNAME in mount volume, e.g.
<code>/log/$HOSTNAME</code></li>
<li>Link the folder: <code>ln -sf /log/$HOSTNAME /med/log</code>.</li>
</ol>

<p>In k8s, you need to mount the host log folder <code>/var/log/k8s/</code> to <code>/log</code>. And the log dir looks like:</p>

<pre><code>/var/log/k8s/
|-- app1-${container_id}/
|   |-- access.log
|   |-- error.log
|-- app2-${container_id}/
    |-- access.log
    |-- error.log
</code></pre>
