kubernetes如何在没有stdout或stderr的情况下收集日志文件 [英] kubernetes how to collect log file without stdout or stderr
问题描述
我的Pod有多个日志文件,例如php-fpm
+ nginx
堆栈.如何收集日志文件?
My pod have more than one log file, such as php-fpm
+ nginx
stack. How to collect the log files?
我知道nginx使用symlink来做到这一点.但这不能处理两个以上的日志文件.
I know nginx doing it with symlink. But this cannot deal with more than 2 log files.
我想将主机中的卷装载到Pod,但是如何为每个Pod设置不同的文件夹?无论如何,是否可以将主机中由podname
命名的文件夹安装到pod文件夹/logs
.
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 提供了一种将文件夹收集到/var/log/containers/
的方法,但我没有认为它可以在kubernetes中使用.
raychaser gave a way to collect folders to /var/log/containers/
, but I don't think it works in kubernetes.
推荐答案
最后,我找到了一种收集日志的方法.
Finally, I find a way to collect the logs.
- 确保所有应用将所有日志文件都写入一个文件夹,例如
/med/log
. - 确保所有应用都使用脚本启动工作,例如
entrypoint.sh
. - 在安装卷中创建一个名为$ HOSTNAME的文件夹,例如
/log/$HOSTNAME
- 链接文件夹:
ln -sf /log/$HOSTNAME /med/log
.
- Make sure all apps write all log files to a folder, e.g.
/med/log
. - Make sure all apps start the job with a script, e.g.
entrypoint.sh
. - Create a folder named by $HOSTNAME in mount volume, e.g.
/log/$HOSTNAME
- Link the folder:
ln -sf /log/$HOSTNAME /med/log
.
在k8s中,您需要将主机日志文件夹/var/log/k8s/
挂载到/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
这篇关于kubernetes如何在没有stdout或stderr的情况下收集日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!