Skip to content

记一次 K8S 节点磁盘占用空间警报的调查

这两天连续发生了几次磁盘占用空间过多的预警,今天调查了一天,发现有两个原因导致了这个问题。

docker overlay2 存储文件过多

其中一个节点上 /var/lib/docker/overlay2 目录占用了绝大多数的磁盘空间。 overlay2 是 docker 的存储系统。

参考 这篇文章 上的命令,清理了磁盘。

  1. du -hs /var/lib/docker/ 查看磁盘使用情况。

  2. docker system df 查看 Docker 的磁盘使用情况。

  3. docker system prune 清理磁盘,删除关闭的容器、无用的数据卷和网络,以及 dangling 镜像 (即无 tag 的镜像)。

  4. docker system prune -a 命令清理得更加彻底,可以将没有容器使用 Docker 镜像都删掉。

    注意

    这两个命令会把你暂时关闭的容器,以及暂时没有用到的 Docker 镜像都删掉。

p6spy 日志

项目采用 dynamic-datasource-spring-boot-starter 实现多数据库的访问,使用 p6spy 来监控 SQL。

由于之前生产环境中错误的开启了 p6spy 监控,而且遗漏了 spy.properties 配置,导致默认情况下日志输出到了根目录的 spy.log 文件。最终这个文件过大,导致 k8s 资源不足,以至驱逐了该节点的所有服务。

修复起来也比加简单:

案 1. 直接关闭 p6spy 监控

生产环境建议是关闭 p6spy 监控的。

properties
datasource.datasource.dynamic.p6spy=false

案 2. 指定 p6spyappender,将日志输出到日志系统

仍然需要监控时,可以通过在 spy.properties 文件中指定 appender 来将日志输出到日志系统。

properties
appender=com.p6spy.engine.spy.appender.Slf4JLogger

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.