Chao Peng
Chao Peng

Reputation: 167

kubernetes how to collect log file without stdout or stderr

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

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

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 podname in the host to pod folder /logs.

raychaser gave a way to collect folders to /var/log/containers/, but I don't think it works in kubernetes.

Upvotes: 4

Views: 4870

Answers (2)

Chao Peng
Chao Peng

Reputation: 167

Finally, I find a way to collect the logs.

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

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

/var/log/k8s/
|-- app1-${container_id}/
|   |-- access.log
|   |-- error.log
|-- app2-${container_id}/
    |-- access.log
    |-- error.log

Upvotes: 3

Javier Salmeron
Javier Salmeron

Reputation: 8835

You can use a logging solution like Fluentd, which allows you to define multiple information sources. As you have several log files it could work for your use case.

http://docs.fluentd.org/v0.12/articles/quickstart http://docs.fluentd.org/v0.12/articles/config-file

Upvotes: 0

Related Questions