128. 如何在 RKE2 或 K3s 集群中更改容器日志级别

张开发
2026/6/12 7:25:29 15 分钟阅读
128. 如何在 RKE2 或 K3s 集群中更改容器日志级别
Procedure 程序The containerd log level can be set to one of the following values: trace, debug, info, warn, error, fatal or panic. In RKE2 and K3s clusters the log level is not explicitly set by default, and so containerd defaults to info level logging. During troubleshooting it may be necessary to capture containerd logs at a more verbose level, such as debug, and this can be achieved as follows.容器日志级别可以设置为以下值之一trace、debug、info、warn、error、fatal 或 panic。在 RKE2 和 K3 集群中日志级别默认未被明确设置因此容器默认为信息级别日志。在排查过程中可能需要以更繁琐的层面捕获容器日志比如调试具体步骤如下。Set the environment variable CONTAINERD_LOG_LEVEL in /etc/default/service-name for the relevant systemd service (rke2-server, rke2-agent or k3s, depending upon the cluster and node type) and restart the service to apply the change:在 /etc/default/ 中为service-name相关 systemd 服务rke2-server、rke2-agent 或 k3s取决于集群和节点类型设置环境变量 CONTAINERD_LOG_LEVEL然后重启服务以应用该更改span stylecolor:#000000span stylebackground-color:#ffffffspan stylebackground-color:#efefefcodeecho CONTAINERD_LOG_LEVELdebug /etc/default/rke2-server/rke2-agent/k3s systemctl restart rke2-server/rke2-agent/k3s/code/span/span/spanThe containerd log file can be found at /var/lib/rancher/rke2/agent/containerd/containerd.log for RKE2 clusters and /var/lib/rancher/k3s/agent/containerd/containerd.log for K3s clusters.容器日志文件可在 /var/lib/rancher/rke2/agent/containerd/containerd.log 找到适用于 RKE2 集群 containerd.log 于 /var/lib/rancher/k3s/agent/containerd/适用于 K3s 集群 。To revert the change later, simply remove the CONTAINERD_LOG_LEVEL line from the /etc/default/service-name file and restart the service again.要以后还原更改只需从/etc/default/文件中移除 CONTAINERD_LOG_LEVEL 行 service-name然后重新启动服务即可。Environment 环境A Rancher-provisioned or standalone RKE2 or K3s clusterRancher 配置或独立的 RKE2 或 K3s 集群访问Rancher-K8S解决方案博主企业合作伙伴 https://blog.csdn.net/lidw2009

更多文章