<p>I have an application which stores logs in a file at a configurable location.
Let's say <code>/abc/pqr/application.log</code></p>
<p>Application is being migrated to Kubernetes where it will run in a single pod. If I run <code>kubectl log &lt;pod-name&gt;</code>, I get anything that gets printed on <code>stdout</code> which I can redirect to a file. I want to do the other way around, I have a file containing logs at above location and I want <code>kubectl logs &lt;pod-name&gt;</code> to print logs from that file.</p>
<p>For example, if run <code>kubectl logs kafka</code> for a kafka pod deployed using <a href="https://github.com/bitnami/charts/tree/master/bitnami/kafka" rel="nofollow noreferrer">bitnami/kafka</a>, I get logs from <code>/opt/bitnami/kafka/logs/server.log</code>. I want to mimic this behavior.</p>

zweack
<p><code>kubectl logs</code> command takes everything from <code>stdout</code> and <code>stderr</code>, so you need to supply logs there.</p>
<p>It's a common practice when containerised applications write their logs to <code>stdout</code> and <code>stderr</code>.</p>
<p>This way there are two main options:</p>
<ol>
<li><p>Adjust the application so it writes logs to <code>stdout</code> and file as well.
E.g. using shell it can be done with <code>tee</code> command.</p>
<p>Please find a <a href="https://stackoverflow.com/questions/418896/how-to-redirect-output-to-a-file-and-stdout">good answers</a> with description of the command.</p>
</li>
<li><p>Use a sidecar container which will be getting logs from file and translating them into its own <code>stdout</code>.
Please find <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/#sidecar-container-with-logging-agent" rel="nofollow noreferrer">Using a sidecar container with the logging agent</a></p>
</li>
</ol>
<p>Useful link about kubernetes logging (including containers):</p>
<ul>
<li><a href="https://sematext.com/guides/kubernetes-logging/#how-does-logging-in-kubernetes-work" rel="nofollow noreferrer">The Complete Guide to Kubernetes Logging</a></li>
</ul>
