<p>I use "<a href="https://hub.docker.com/r/chentex/random-logger/" rel="nofollow noreferrer">chentex/random-logger</a>" image, which write stdout/stderr to the container. I want to make deployment yaml, which run the chentex's image, and put it's logs in file inside shared volume. Can I do it without modifying the image?</p>

<p>This is the simple deployment of the image:</p>

<pre><code>apiVersion: v1
kind: Deployment
metadata:
  name: random-logger
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: random-logger
    spec:
      containers:
      - name: random-logger
        image: chentex/random-logger:latest
</code></pre>

Yagel
<p>It is best practice to send log message to <code>stdout</code> for applications running in a container. The <code>chentex/random-logger</code> just <a href="https://github.com/chentex/random-logger/blob/master/entrypoint.sh#L10-L16" rel="nofollow noreferrer">follows this approach</a> without any option to configure this, but we can bring up a hack like this:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: random-logger
spec:
  selector:
    matchLabels:
      app: random-logger
  template:
    metadata:
      labels:
        app: random-logger
    spec:
      containers:
      - name: random-logger
        image: chentex/random-logger:latest
        command: ["sh", "-c",  "./entrypoint.sh &amp;&gt; /logfile"]
</code></pre>

<p>When requesting the logs from the running <code>pod</code> there is nothing to see:</p>

<pre class="lang-sh prettyprint-override"><code>$ kubectl logs random-logger-76c6fd98d5-8d5fm
</code></pre>

<p>The application logs are written to <code>logfile</code> within the container:</p>

<pre class="lang-sh prettyprint-override"><code>$ kubectl exec random-logger-76c6fd98d5-8d5fm cat /logfile
2019-02-28T00:23:23+0000 DEBUG first loop completed.
2019-02-28T00:23:25+0000 ERROR something happened in this execution.
2019-02-28T00:23:29+0000 INFO takes the value and converts it to string.
2019-02-28T00:23:31+0000 WARN variable not in use.
2019-02-28T00:23:37+0000 INFO takes the value and converts it to string.
</code></pre>

<p>Although this is possible, it is in general not advised. See the Kubernetes documentation about <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/" rel="nofollow noreferrer">Logging Architecture</a> for more background information.</p>
