From 60d9d0839606e89db992f033053d44debd03a21a Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Sun, 21 Apr 2024 20:30:58 +0800 Subject: [PATCH] [zh-cn] sync logging system-logs Signed-off-by: xin.li --- .../cluster-administration/logging.md | 73 +++++++++++++++---- .../cluster-administration/system-logs.md | 34 +++++---- 2 files changed, 78 insertions(+), 29 deletions(-) diff --git a/content/zh-cn/docs/concepts/cluster-administration/logging.md b/content/zh-cn/docs/concepts/cluster-administration/logging.md index 0212ffe3db..9e92191aec 100644 --- a/content/zh-cn/docs/concepts/cluster-administration/logging.md +++ b/content/zh-cn/docs/concepts/cluster-administration/logging.md @@ -180,16 +180,32 @@ You can configure two kubelet [configuration settings](/docs/reference/config-ap using the [kubelet configuration file](/docs/tasks/administer-cluster/kubelet-config-file/). These settings let you configure the maximum size for each log file and the maximum number of files allowed for each container respectively. +--> +你可以使用 [kubelet 配置文件](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/)配置两个 +kubelet [配置选项](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-KubeletConfiguration)、 +`containerLogMaxSize` (默认 10Mi)和 `containerLogMaxFiles`(默认 5)。 +这些设置分别允许你分别配置每个日志文件大小的最大值和每个容器允许的最大文件数。 + +为了在工作负载生成的日志量较大的集群中执行高效的日志轮换,kubelet +还提供了一种机制,基于可以执行多少并发日志轮换以及监控和轮换日志所需要的间隔来调整日志的轮换方式。 +你可以使用 [kubelet 配置文件](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/) +配置两个 kubelet [配置选项](/zh-cn/docs/tasks/administer-cluster/kubelet-config-file/): +`containerLogMaxWorkers` 和 `containerLogMonitorInterval`。 + + -你可以使用 [kubelet 配置文件](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/)配置两个 -kubelet [配置选项](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-KubeletConfiguration)、 -`containerLogMaxSize` (默认 10Mi)和 `containerLogMaxFiles` (默认 5)。 -这些设置分别允许你分别配置每个日志文件大小的最大值和每个容器允许的最大文件数。 - 当类似于基本日志示例一样运行 [`kubectl logs`](/docs/reference/generated/kubectl/kubectl-commands#logs) 时, 节点上的 kubelet 会处理请求并直接从日志文件读取。kubelet 将返回该日志文件的内容。 @@ -262,12 +278,12 @@ kubelet logs to a directory that you choose. 并使用该工具将 kubelet 日志重定向到你所选择的目录。 -kubelet 始终指示你的容器运行时将日志写入 `/var/log/pods` 中的目录。 +默认情况下,kubelet 指示你的容器运行时将日志写入 `/var/log/pods` 中的目录。 有关 `kube-log-runner` 的更多信息,请阅读[系统日志](/zh-cn/docs/concepts/cluster-administration/system-logs/#klog)。 @@ -291,7 +307,7 @@ If you want to have logs written elsewhere, you can indirectly run the kubelet via a helper tool, `kube-log-runner`, and use that tool to redirect kubelet logs to a directory that you choose. -However, the kubelet always directs your container runtime to write logs within the +However, by default, kubelet directs your container runtime to write logs within the directory `C:\var\log\pods`. For more information on `kube-log-runner`, read [System Logs](/docs/concepts/cluster-administration/system-logs/#klog). @@ -299,7 +315,7 @@ For more information on `kube-log-runner`, read [System Logs](/docs/concepts/clu 如果你想将日志写入其他地方,你可以通过辅助工具 `kube-log-runner` 间接运行 kubelet, 并使用该工具将 kubelet 日志重定向到你所选择的目录。 -但是,kubelet 总是指示你的容器运行时在目录 `C:\var\log\pods` 中写入日志。 +但是,kubelet 默认指示你的容器运行时在目录 `C:\var\log\pods` 中写入日志。 有关 `kube-log-runner` 的更多信息,请阅读[系统日志](/zh-cn/docs/concepts/cluster-administration/system-logs/#klog)。 {{% /tab %}} @@ -312,15 +328,44 @@ For Kubernetes cluster components that run in pods, these write to files inside the `/var/log` directory, bypassing the default logging mechanism (the components do not write to the systemd journal). You can use Kubernetes' storage mechanisms to map persistent storage into the container that runs the component. - -For details about etcd and its logs, view the [etcd documentation](https://etcd.io/docs/). -Again, you can use Kubernetes' storage mechanisms to map persistent storage into -the container that runs the component. --> 对于在 Pod 中运行的 Kubernetes 集群组件,其日志会写入 `/var/log` 目录中的文件, 相当于绕过默认的日志机制(组件不会写入 systemd 日志)。 你可以使用 Kubernetes 的存储机制将持久存储映射到运行该组件的容器中。 + +kubelet 允许将 Pod 日志目录从默认的 `/var/log/pods` 更改为自定义路径。 +可以通过在 kubelet 的配置文件中配置 `podLogsDir` 参数来进行此调整。 + +{{< caution >}} + +需要注意的是,默认位置 `/var/log/pods` 已使用很长一段时间,并且某些进程可能会隐式使用此路径。 +因此,更改此参数必须谨慎,并自行承担风险。 + + +另一个需要留意的问题是 kubelet 支持日志写入位置与 `/var` 位于同一磁盘上。 +否则,如果日志位于与 `/var` 不同的文件系统上,kubelet +将不会跟踪该文件系统的使用情况。如果文件系统已满,则可能会出现问题。 +{{< /caution >}} + + 有关 etcd 及其日志的详细信息,请查阅 [etcd 文档](https://etcd.io/docs/)。 同样,你可以使用 Kubernetes 的存储机制将持久存储映射到运行该组件的容器中。 @@ -339,7 +384,7 @@ Some deploy tools account for that log rotation and automate it; others leave th as your responsibility. --> 如果你部署 Kubernetes 集群组件(例如调度器)以将日志记录到从父节点共享的卷中, -则需要考虑并确保这些日志被轮转。 **Kubernetes 不管理这种日志轮转**。 +则需要考虑并确保这些日志被轮转。**Kubernetes 不管理这种日志轮转**。 你的操作系统可能会自动实现一些日志轮转。例如,如果你将目录 `/var/log` 共享到一个组件的静态 Pod 中, 则节点级日志轮转会将该目录中的文件视同为 Kubernetes 之外的组件所写入的文件。 diff --git a/content/zh-cn/docs/concepts/cluster-administration/system-logs.md b/content/zh-cn/docs/concepts/cluster-administration/system-logs.md index 80113d570c..5690d77937 100644 --- a/content/zh-cn/docs/concepts/cluster-administration/system-logs.md +++ b/content/zh-cn/docs/concepts/cluster-administration/system-logs.md @@ -207,7 +207,7 @@ second line.} --> ### 上下文日志 {#contextual-logging} -{{< feature-state for_k8s_version="v1.24" state="alpha" >}} +{{< feature-state for_k8s_version="v1.30" state="beta" >}} -目前这一特性是由 `StructuredLogging` 特性门控所控制的,默认关闭。 +对于 Kubernetes {{< skew currentVersion >}},这一特性是由 `StructuredLogging` +[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)所控制的,默认启用。 这个基础设施是在 1.24 中被添加的,并不需要修改组件。 该 [`component-base/logs/example`](https://github.com/kubernetes/kubernetes/blob/v1.24.0-beta.0/staging/src/k8s.io/component-base/logs/example/cmd/logger.go) 命令演示了如何使用新的日志记录调用以及组件如何支持上下文日志记录。 @@ -248,15 +250,15 @@ $ go run . --help --feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: AllAlpha=true|false (ALPHA - default=false) AllBeta=true|false (BETA - default=false) - ContextualLogging=true|false (ALPHA - default=false) + ContextualLogging=true|false (BETA - default=true) $ go run . --feature-gates ContextualLogging=true ... -I0404 18:00:02.916429 451895 logger.go:94] "example/myname: runtime" foo="bar" duration="1m0s" -I0404 18:00:02.916447 451895 logger.go:95] "example: another runtime" foo="bar" duration="1m0s" +I0222 15:13:31.645988 197901 example.go:54] "runtime" logger="example.myname" foo="bar" duration="1m0s" +I0222 15:13:31.646007 197901 example.go:55] "another runtime" logger="example" foo="bar" duration="1h0m0s" duration="1m0s" ``` -`example` 前缀和 `foo="bar"` 会被函数的调用者添加上, +`logger` 键和 `foo="bar"` 会被函数的调用者添加上, 不需修改该函数,它就会记录 `runtime` 消息和 `duration="1m0s"` 值。 禁用上下文日志后,`WithValues` 和 `WithName` 什么都不会做, @@ -274,8 +276,8 @@ is not in the log output anymore: ```console $ go run . --feature-gates ContextualLogging=false ... -I0404 18:03:31.171945 452150 logger.go:94] "runtime" duration="1m0s" -I0404 18:03:31.171962 452150 logger.go:95] "another runtime" duration="1m0s" +I0222 15:14:40.497333 198174 example.go:54] "runtime" duration="1m0s" +I0222 15:14:40.497346 198174 example.go:55] "another runtime" duration="1h0m0s" duration="1m0s" ``` 为了帮助在节点上调试问题,Kubernetes v1.27 引入了一个特性来查看节点上当前运行服务的日志。 @@ -419,7 +421,7 @@ in the application log provider. On both operating systems, logs are also availa 在两种操作系统上,都可以通过读取 `/var/log/` 内的文件查看日志。 -假如你被授权与节点对象交互,你可以在所有节点或只是某个子集上试用此 Alpha 特性。 +假如你被授权与节点对象交互,你可以在所有节点或只是某个子集上试用此特性。 这里有一个从节点中检索 kubelet 服务日志的例子: ```shell @@ -504,10 +506,12 @@ kubectl get --raw "/api/v1/nodes/node-1.example/proxy/logs/?query=kubelet&patter * Read about [Contextual Logging](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging) * Read about [deprecation of klog flags](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components) * Read about the [Conventions for logging severity](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md) +* Read about [Log Query](https://kep.k8s.io/2258) --> * 阅读 [Kubernetes 日志架构](/zh-cn/docs/concepts/cluster-administration/logging/) * 阅读[结构化日志提案(英文)](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging) * 阅读[上下文日志提案(英文)](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging) * 阅读 [klog 参数的废弃(英文)](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components) * 阅读[日志严重级别约定(英文)](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md) +* 阅读[日志查询](https://kep.k8s.io/2258)