简体   繁体   English

Kube.netes 在容器中获取日志

[英]Kubernetes get log within container

Background: I use glog to register signal handler, but it cannot kill the init process (PID=1) with kill sigcall.背景:我使用 glog 来注册信号处理程序,但它无法使用kill sigcall 终止 init 进程 (PID=1)。 That way, even though deadly signals like SIGABRT is raised, kube.netes controller manager won't be able to understand the pod is actually not functioning, thus kill the pod and restart a new one.这样,即使发出像SIGABRT这样的致命信号,kube.netes controller 管理器也无法理解 pod 实际上没有运行,因此杀死 pod 并重新启动一个新的 pod。

My idea is to add logic into my readiness/liveness probe: check the content for current container, whether it's in healthy state.我的想法是将逻辑添加到我的就绪/活性探测中:检查当前容器的内容,是否处于健康状态 state。

I'm trying to look into the logs on container's local filesystem /var/log , but haven't found anything useful.我正在尝试查看容器本地文件系统/var/log上的日志,但没有发现任何有用的信息。

I'm wondering if it's possible to issue a HTTP request to somewhere, to get the complete log?我想知道是否可以向某个地方发出 HTTP 请求,以获取完整的日志? I assume it's stored somewhere.我假设它存储在某个地方。

You can find the kube.netes logs on Master machine at:您可以在Master机器上找到 kube.netes 日志:

/var/log/pods /var/日志/豆荚

if using docker containers:如果使用 docker 容器:

/var/lib/docker/containers /var/lib/docker/容器

Containers are Ephemeral容器是短暂的

Docker containers emit logs to the stdout and stderr output streams. Docker 容器将日志发送到stdoutstderr output 流。 Because containers are stateless, the logs are stored on the Docker host in JSON files by default.因为容器是无状态的,日志默认保存在Docker主机上的JSON files中。

The default logging driver is json-file.默认的日志记录驱动程序是 json 文件。 The logs are then annotated with the log origin, either stdout or stderr, and a timestamp.然后用日志来源(stdout 或 stderr)和时间戳对日志进行注释。 Each log file contains information about only one container.每个日志文件仅包含有关一个容器的信息。

As @Uri Loya said, You can find these JSON log files in /var/lib/docker/containers/ directory on a Linux Docker host.正如@Uri Loya 所说,您可以在 Linux Docker 主机上的 /var/lib/docker/containers/ 目录中找到这些 JSON 日志文件。 Here's how you can access them:您可以通过以下方式访问它们:

/var/lib/docker/containers/<container id>/<container id>-json.log

You can collect the logs with a log aggregator and store them in a place where they'll be available forever.您可以使用日志聚合器收集日志并将它们存储在可以永久使用的地方。 It's dangerous to keep logs on the Docker host because they can build up over time and eat into your disk space.将日志保存在 Docker 主机上是很危险的,因为它们会随着时间的推移而累积并占用您的磁盘空间。 That's why you should use a central location for your logs and enable log rotation for your Docker containers.这就是为什么您应该为日志使用中央位置并为 Docker 容器启用日志轮换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM