k8s 对容器的日志有什么特殊的处理么?dashboad 日志输出和本地 docker 运行 表现不一致

191 天前
 Aruforce

当我登入容器 向追踪的文件

echo "123123213" >> /var/log/tac_plus/access/access.log

k8s dashboard 日志并没有输出 但是本地是可以的 如下是我的脚本,是我写错了 还是 k8s 对容器的日志有特别的处理?

Dokerfile

FROM ubuntu:20.04
RUN mkdir -p /var/log/tac_plus/access/
RUN mkdir -p /var/log/tac_plus/accounting/
RUN mkdir -p /var/log/tac_plus/authentication/
RUN mkdir -p /var/log/tac_plus/authorization/
ADD ./access.log /var/log/tac_plus/access/access.log
ADD ./accounting.log /var/log/tac_plus/accounting/accounting.log
ADD ./authentication.log /var/log/tac_plus/authentication/authentication.log
ADD ./authorization.log /var/log/tac_plus/authorization/authorization.log
ADD ./docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
CMD ["bash","-c","/docker-entrypoint.sh"]

docker-entrypoint

#!/bin/sh
echo "Starting server..."
{
        tail -f /var/log/tac_plus/access/access.log
}&

{
        tail -f /var/log/tac_plus/accounting/accounting.log
}&

{
        tail -f /var/log/tac_plus/authentication/authentication.log
}
1937 次点击
所在节点    Kubernetes
49 条回复
julyclyde
191 天前
啥叫“本地”?

你为什么假定“那个文件”就是 k8s dashboard 读的文件?
Aruforce
191 天前
@julyclyde 本地是指 本地 docker 运行
k58s dashboard 日志 读取不是容器的 stdout 么?
Aruforce
191 天前
@julyclyde 本地是指 本地 docker 运行
k8s dashboard 日志 读取不是容器的 stdout 么?
julyclyde
191 天前
@Aruforce 你既然知道是 stdout ,为什么想着往 access.log 里加内容呢?
Aruforce
191 天前
@julyclyde 我用 tail 输出到 stdout 的啊
Aruforce
191 天前
@julyclyde 你看启动的 shell 脚本
julyclyde
191 天前
@Aruforce 那你试试用 strace 验证一下,tail 有没有读到这一行,有没有把这一行输出到 stdout
seers
191 天前
你往 auth 写一条看看,第三个 tail 可能覆盖掉了你的前两个 stdout
nuII
191 天前
docker 的日志是抓取 stdout 然后写入到多行 json 格式组成的文件里,k8s 和 docker 的日志查看都是去读这个容器的日志文件,你得看日志文件里有没有,可以用 docker inspect {container id}来看日志文件的位置。另外你这个 dockerfile 用法不太规范,直接 add 可能会有权限问题,你看看你容器是 root 运行的吗,不是的话可能写不进去。
Aruforce
191 天前
@seers k8s 上都不行 本地 docker 都可以输出…
julyclyde
191 天前
@seers 为什么第三个会覆盖前两个呢?不明白
Aruforce
191 天前
@julyclyde fstat(3, 0x7fff7454e7e0) = -1 ENOSYS (Function not implemented)
Aruforce
191 天前
@julyclyde 你好 我追了下 tail 似乎是 对 stat read 两个方法没有实现?
julyclyde
191 天前
@Aruforce 那你在 kubernetes 里运行用的是哪种 container runtime 呢?是 containerD 吗?看看具体用了哪种文件系统?
Aruforce
191 天前
@julyclyde Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020
Aruforce
191 天前
@julyclyde 内核版本太低了么?
Aruforce
191 天前
@Aruforce 10
@julyclyde 文件系统
```
root@demo-f996b8cff-g45rr:/# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
overlay overlay 314418180 75916068 238502112 25% /
tmpfs tmpfs 65536 0 65536 0% /dev
tmpfs tmpfs 8128524 0 8128524 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17811456 14392760 3418696 81% /etc/hosts
/dev/vdb1 xfs 314418180 75916068 238502112 25% /etc/hostname
shm tmpfs 65536 0 65536 0% /dev/shm
tmpfs tmpfs 15949852 12 15949840 1% /run/secrets/kubernetes.io/serviceaccount
tmpfs tmpfs 8128524 0 8128524 0% /proc/acpi
tmpfs tmpfs 8128524 0 8128524 0% /proc/scsi
tmpfs tmpfs 8128524 0 8128524 0% /sys/firmware
```
julyclyde
191 天前
对比一下正常的 docker 呢?是什么版本、什么文件系统?
julyclyde
191 天前
看一下出错的机器的 dmesg
有没有文件系统相关的错误日志
Aruforce
191 天前
@julyclyde docker 版本都是 24.0.5 系统内核吧版本差别比较大…集群里的还是 3.1.0 找了 4.19 和 5.10 系统跑本地都没啥问题

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/987333

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX