<p>i'm stack at k8s log storage.we have logs that can't output to stdout,but have to save to dir.we want to save to glusterfs shared dir like /data/logs/./xxx.log our apps are written in java ,how can we do that</p>

tennis wang
<p>I had the same problem with one 3rd party application. It was writing logs in a log file and I wanted Fluentd to be able to get them so I wanted somehow to print them on the stdout.
I found a workaround with one additional container running alongside with the app container in the same pod.</p>

<p>Lets say the 3rd party app is writing logs in the following file: </p>

<blockquote>
  <p>/some/folders/logs/app_log_file.log</p>
</blockquote>

<p>The following pod will run two containers, one with the app and the other with busybox image which we will use to fetch the logs from the app container.</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: application-pod
spec:
  containers:
  - name: app-container
    image: &lt;path-to-app-image&gt;
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: log-volume
      mountPath: /some/folders/logs
  - name: log-fetcher-container
    image: busybox
    args: [/bin/sh, -c, 'sleep 60 &amp;&amp; tail -n+1 -f /var/log/app_log_file.log']
    volumeMounts:
    - name: log-volume
      mountPath: /var/log
  volumes:
  - name: log-volume
    emptyDir: {}
</code></pre>

<p>As you can see this manifest is creating a empty volume and mounting volume to the /some/folders/logs folder in the app container and to the /var/log folder in the log fetcher container. Now every file that the app container writes to /some/folders/logs will be visible in /var/log also.
That's why the busybox image is running a shell command:</p>

<pre><code>sleep 60 &amp;&amp; tail -n+1 -f /var/log/app_log_file.log
</code></pre>

<p>First we wait 60 seconds because the app container must have time to start up and create the log file and then the tail command is going to print every new line in the log file to the stdout of the log fetcher container.</p>

<p>And now the fluentd will be able to get the logs from the log file of the app container getting the stdout logs of the log fetcher container.</p>
