Merge pull request #45947 from my-git9/logging-234

[zh-cn] sync logging system-logs
This commit is contained in:
Kubernetes Prow Robot 2024-04-21 17:54:55 -07:00 committed by GitHub
commit e88e8da44f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 78 additions and 29 deletions

View File

@ -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
这些设置分别允许你分别配置每个日志文件大小的最大值和每个容器允许的最大文件数。
<!--
In order to perform an efficient log rotation in clusters where the volume of the logs generated by
the workload is large, kubelet also provides a mechanism to tune how the logs are rotated in
terms of how many concurrent log rotations can be performed and the interval at which the logs are
monitored and rotated as required.
You can configure two kubelet [configuration settings](/docs/reference/config-api/kubelet-config.v1beta1/),
`containerLogMaxWorkers` and `containerLogMonitorInterval` using the
[kubelet configuration file](/docs/tasks/administer-cluster/kubelet-config-file/).
-->
为了在工作负载生成的日志量较大的集群中执行高效的日志轮换kubelet
还提供了一种机制,基于可以执行多少并发日志轮换以及监控和轮换日志所需要的间隔来调整日志的轮换方式。
你可以使用 [kubelet 配置文件](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/)
配置两个 kubelet [配置选项](/zh-cn/docs/tasks/administer-cluster/kubelet-config-file/)
`containerLogMaxWorkers``containerLogMonitorInterval`
<!--
When you run [`kubectl logs`](/docs/reference/generated/kubectl/kubectl-commands#logs) as in
the basic logging example, the kubelet on the node handles the request and
reads directly from the log file. The kubelet returns the content of the log file.
-->
你可以使用 [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 日志重定向到你所选择的目录。
<!--
The kubelet always directs your container runtime to write logs into directories within
By default, kubelet directs your container runtime to write logs into directories within
`/var/log/pods`.
For more information on `kube-log-runner`, read [System Logs](/docs/concepts/cluster-administration/system-logs/#klog).
-->
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 allows changing the pod logs directory from default `/var/log/pods`
to a custom path. This adjustment can be made by configuring the `podLogsDir`
parameter in the kubelet's configuration file.
-->
kubelet 允许将 Pod 日志目录从默认的 `/var/log/pods` 更改为自定义路径。
可以通过在 kubelet 的配置文件中配置 `podLogsDir` 参数来进行此调整。
{{< caution >}}
<!--
It's important to note that the default location `/var/log/pods` has been in use for
an extended period and certain processes might implicitly assume this path.
Therefore, altering this parameter must be approached with caution and at your own risk.
-->
需要注意的是,默认位置 `/var/log/pods` 已使用很长一段时间,并且某些进程可能会隐式使用此路径。
因此,更改此参数必须谨慎,并自行承担风险。
<!--
Another caveat to keep in mind is that the kubelet supports the location being on the same
disk as `/var`. Otherwise, if the logs are on a separate filesystem from `/var`,
then the kubelet will not track that filesystem's usage, potentially leading to issues if
it fills up.
-->
另一个需要留意的问题是 kubelet 支持日志写入位置与 `/var` 位于同一磁盘上。
否则,如果日志位于与 `/var` 不同的文件系统上kubelet
将不会跟踪该文件系统的使用情况。如果文件系统已满,则可能会出现问题。
{{< /caution >}}
<!--
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.
-->
有关 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 之外的组件所写入的文件。

View File

@ -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" >}}
<!--
Contextual logging builds on top of structured logging. It is primarily about
@ -229,14 +229,16 @@ passed into functions by their caller.
那么日志条目将会包含额外的信息,这些信息会被调用者传递给函数。
<!--
Currently this is gated behind the `StructuredLogging` feature gate and
disabled by default. The infrastructure for this was added in 1.24 without
For Kubernetes {{< skew currentVersion >}}, this is gated behind the `ContextualLogging`
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) and is
enabled by default. The infrastructure for this was added in 1.24 without
modifying components. The
[`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)
command demonstrates how to use the new logging calls and how a component
behaves that supports contextual logging.
-->
目前这一特性是由 `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"
```
<!--
The `example` prefix and `foo="bar"` were added by the caller of the function
The `logger` key and `foo="bar"` were added by the caller of the function
which logs the `runtime` message and `duration="1m0s"` value, without having to
modify that function.
@ -264,7 +266,7 @@ With contextual logging disable, `WithValues` and `WithName` do nothing and log
calls go through the global klog logger. Therefore this additional information
is not in the log output anymore:
-->
`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"
```
<!--
@ -406,8 +408,8 @@ To help with debugging issues on nodes, Kubernetes v1.27 introduced a feature th
running on the node. To use the feature, ensure that the `NodeLogQuery`
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled for that node, and that the
kubelet configuration options `enableSystemLogHandler` and `enableSystemLogQuery` are both set to true. On Linux
we assume that service logs are available via journald. On Windows we assume that service logs are available
in the application log provider. On both operating systems, logs are also available by reading files within
the assumption is that service logs are available via journald. On Windows the assumption is that service logs are
available in the application log provider. On both operating systems, logs are also available by reading files within
`/var/log/`.
-->
为了帮助在节点上调试问题Kubernetes v1.27 引入了一个特性来查看节点上当前运行服务的日志。
@ -419,7 +421,7 @@ in the application log provider. On both operating systems, logs are also availa
在两种操作系统上,都可以通过读取 `/var/log/` 内的文件查看日志。
<!--
Provided you are authorized to interact with node objects, you can try out this alpha feature on all your nodes or
Provided you are authorized to interact with node objects, you can try out this feature on all your nodes or
just a subset. Here is an example to retrieve the kubelet service logs from a node:
```shell
@ -427,7 +429,7 @@ just a subset. Here is an example to retrieve the kubelet service logs from a no
kubectl get --raw "/api/v1/nodes/node-1.example/proxy/logs/?query=kubelet"
```
-->
假如你被授权与节点对象交互,你可以在所有节点或只是某个子集上试用此 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)