无需重新启动守护程序即可重新加载 docker 日志记录配置

Sil*_*sky 8 logging docker kubernetes

我有一些正在运行的 kubernetes 集群,它可能会产生大量日志。Kubernetes 运行在 docker 之上,所以我想我需要配置 dockerd 来推出日志

我找到了一些 dockerd 日志驱动程序的设置:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10k",
    "max-file": "2"
  }
}
Run Code Online (Sandbox Code Playgroud)

在 docker 服务重启的情况下,更改成功应用。

du /var/lib/docker/containers/container_hash/container_hash* -h
Run Code Online (Sandbox Code Playgroud)

显示按适当大小分块的日志文件。

但我不想重新启动守护进程,所以尝试重新加载配置:

sudo kill -SIGHUP $(pidof dockerd)
Run Code Online (Sandbox Code Playgroud)

在系统日志中我发现:

Mar 12 15:38:16 kso-gl dockerd[5331]: time="2018-03-12T15:38:16.446894155+02:00" level=info msg="Got signal to reload configuration, reloading fr
om: /etc/docker/daemon.json"
Run Code Online (Sandbox Code Playgroud)

所以,我假设配置已重新加载。不幸的是它没有效果。即使是新的容器。看起来与日志驱动程序相关的子系统忽略了配置重新加载。

lev*_*ker 13

遗憾的是,似乎配置重新加载 SIGHUP 功能不支持所有配置选项。

https://docs.docker.com/v17.09/engine/reference/commandline/dockerd/#miscellaneous-options 上的文档(请参阅“配置重新加载行为”部分)告诉我们可以重新加载的唯一支持的配置选项这种方式是:

The list of currently supported options that can be reconfigured is this:

debug: it changes the daemon to debug mode when set to true.
cluster-store: it reloads the discovery store with the new address.
cluster-store-opts: it uses the new options to reload the discovery store.
cluster-advertise: it modifies the address advertised after reloading.
labels: it replaces the daemon labels with a new set of labels.
live-restore: Enables keeping containers alive during daemon downtime.
max-concurrent-downloads: it updates the max concurrent downloads for each pull.
max-concurrent-uploads: it updates the max concurrent uploads for each push.
default-runtime: it updates the runtime to be used if not is specified at container creation. It defaults to “default” which is the runtime shipped with the official docker packages.
runtimes: it updates the list of available OCI runtimes that can be used to run containers
authorization-plugin: specifies the authorization plugins to use.
allow-nondistributable-artifacts: Replaces the set of registries to which the daemon will push nondistributable artifacts with a new set of registries.
insecure-registries: it replaces the daemon insecure registries with a new set of insecure registries. If some existing insecure registries in daemon’s configuration are not in newly reloaded insecure resgitries, these existing ones will be removed from daemon’s config.
registry-mirrors: it replaces the daemon registry mirrors with a new set of registry mirrors. If some existing registry mirrors in daemon’s configuration are not in newly reloaded registry mirrors, these existing ones will be removed from daemon’s config.
Run Code Online (Sandbox Code Playgroud)

如您所见,其中不包括log-driverlog-opts配置参数。

目前,我不知道有什么方法可以在不重启的情况下重新加载日志记录配置。