Skip to content

Commit 60d9d08

Browse files
committed
[zh-cn] sync logging system-logs
Signed-off-by: xin.li <xin.li@daocloud.io>
1 parent 9a9038f commit 60d9d08

File tree

2 files changed

+78
-29
lines changed

2 files changed

+78
-29
lines changed

‎content/zh-cn/docs/concepts/cluster-administration/logging.md

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,32 @@ You can configure two kubelet [configuration settings](/docs/reference/config-ap
180180
using the [kubelet configuration file](/docs/tasks/administer-cluster/kubelet-config-file/).
181181
These settings let you configure the maximum size for each log file and the maximum number of
182182
files allowed for each container respectively.
183-
184-
When you run [`kubectl logs`](/docs/reference/generated/kubectl/kubectl-commands#logs) as in
185-
the basic logging example, the kubelet on the node handles the request and
186-
reads directly from the log file. The kubelet returns the content of the log file.
187183
-->
188184
你可以使用 [kubelet 配置文件](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/)配置两个
189185
kubelet [配置选项](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-KubeletConfiguration)
190-
`containerLogMaxSize` (默认 10Mi)和 `containerLogMaxFiles` (默认 5)。
186+
`containerLogMaxSize` (默认 10Mi)和 `containerLogMaxFiles`(默认 5)。
191187
这些设置分别允许你分别配置每个日志文件大小的最大值和每个容器允许的最大文件数。
192188

189+
<!--
190+
In order to perform an efficient log rotation in clusters where the volume of the logs generated by
191+
the workload is large, kubelet also provides a mechanism to tune how the logs are rotated in
192+
terms of how many concurrent log rotations can be performed and the interval at which the logs are
193+
monitored and rotated as required.
194+
You can configure two kubelet [configuration settings](/docs/reference/config-api/kubelet-config.v1beta1/),
195+
`containerLogMaxWorkers` and `containerLogMonitorInterval` using the
196+
[kubelet configuration file](/docs/tasks/administer-cluster/kubelet-config-file/).
197+
-->
198+
为了在工作负载生成的日志量较大的集群中执行高效的日志轮换,kubelet
199+
还提供了一种机制,基于可以执行多少并发日志轮换以及监控和轮换日志所需要的间隔来调整日志的轮换方式。
200+
你可以使用 [kubelet 配置文件](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/)
201+
配置两个 kubelet [配置选项](/zh-cn/docs/tasks/administer-cluster/kubelet-config-file/)
202+
`containerLogMaxWorkers``containerLogMonitorInterval`
203+
204+
<!--
205+
When you run [`kubectl logs`](/docs/reference/generated/kubectl/kubectl-commands#logs) as in
206+
the basic logging example, the kubelet on the node handles the request and
207+
reads directly from the log file. The kubelet returns the content of the log file.
208+
-->
193209
当类似于基本日志示例一样运行 [`kubectl logs`](/docs/reference/generated/kubectl/kubectl-commands#logs) 时,
194210
节点上的 kubelet 会处理请求并直接从日志文件读取。kubelet 将返回该日志文件的内容。
195211

@@ -262,12 +278,12 @@ kubelet logs to a directory that you choose.
262278
并使用该工具将 kubelet 日志重定向到你所选择的目录。
263279

264280
<!--
265-
The kubelet always directs your container runtime to write logs into directories within
281+
By default, kubelet directs your container runtime to write logs into directories within
266282
`/var/log/pods`.
267283
268284
For more information on `kube-log-runner`, read [System Logs](/docs/concepts/cluster-administration/system-logs/#klog).
269285
-->
270-
kubelet 始终指示你的容器运行时将日志写入 `/var/log/pods` 中的目录。
286+
默认情况下,kubelet 指示你的容器运行时将日志写入 `/var/log/pods` 中的目录。
271287

272288
有关 `kube-log-runner` 的更多信息,请阅读[系统日志](/zh-cn/docs/concepts/cluster-administration/system-logs/#klog)
273289

@@ -291,15 +307,15 @@ If you want to have logs written elsewhere, you can indirectly
291307
run the kubelet via a helper tool, `kube-log-runner`, and use that tool to redirect
292308
kubelet logs to a directory that you choose.
293309
294-
However, the kubelet always directs your container runtime to write logs within the
310+
However, by default, kubelet directs your container runtime to write logs within the
295311
directory `C:\var\log\pods`.
296312
297313
For more information on `kube-log-runner`, read [System Logs](/docs/concepts/cluster-administration/system-logs/#klog).
298314
-->
299315
如果你想将日志写入其他地方,你可以通过辅助工具 `kube-log-runner` 间接运行 kubelet,
300316
并使用该工具将 kubelet 日志重定向��你所选择的目录。
301317

302-
但是,kubelet 总是指示你的容器运行时在目录 `C:\var\log\pods` 中写入日志。
318+
但是,kubelet 默认指示你的容器运行时在目录 `C:\var\log\pods` 中写入日志。
303319

304320
有关 `kube-log-runner` 的更多信息,请阅读[系统日志](/zh-cn/docs/concepts/cluster-administration/system-logs/#klog)
305321
{{% /tab %}}
@@ -312,15 +328,44 @@ For Kubernetes cluster components that run in pods, these write to files inside
312328
the `/var/log` directory, bypassing the default logging mechanism (the components
313329
do not write to the systemd journal). You can use Kubernetes' storage mechanisms
314330
to map persistent storage into the container that runs the component.
315-
316-
For details about etcd and its logs, view the [etcd documentation](https://etcd.io/docs/).
317-
Again, you can use Kubernetes' storage mechanisms to map persistent storage into
318-
the container that runs the component.
319331
-->
320332
对于在 Pod 中运行的 Kubernetes 集群组件,其日志会写入 `/var/log` 目录中的文件,
321333
相当于绕过默认的日志机制(组件不会写入 systemd 日志)。
322334
你可以使用 Kubernetes 的存储机制将持久存储映射到运行该组件的容器中。
323335

336+
<!--
337+
Kubelet allows changing the pod logs directory from default `/var/log/pods`
338+
to a custom path. This adjustment can be made by configuring the `podLogsDir`
339+
parameter in the kubelet's configuration file.
340+
-->
341+
kubelet 允许将 Pod 日志目录从默认的 `/var/log/pods` 更改为自定义路径。
342+
可以通过在 kubelet 的配置文件中配置 `podLogsDir` 参数来进行此调整。
343+
344+
{{< caution >}}
345+
<!--
346+
It's important to note that the default location `/var/log/pods` has been in use for
347+
an extended period and certain processes might implicitly assume this path.
348+
Therefore, altering this parameter must be approached with caution and at your own risk.
349+
-->
350+
需要注意的是,默认位置 `/var/log/pods` 已使用很长一段时间,并且某些进程可能会隐式使用此路径。
351+
因此,更改此参数必须谨慎,并自行承担风险。
352+
353+
<!--
354+
Another caveat to keep in mind is that the kubelet supports the location being on the same
355+
disk as `/var`. Otherwise, if the logs are on a separate filesystem from `/var`,
356+
then the kubelet will not track that filesystem's usage, potentially leading to issues if
357+
it fills up.
358+
-->
359+
另一个需要留意的问题是 kubelet 支持日志写入位置与 `/var` 位于同一磁盘上。
360+
否则,如果日志位于与 `/var` 不同的文件系统上,kubelet
361+
将不会跟踪该文件系统的使用情况。如果文件系统已满,则可能会出现问题。
362+
{{< /caution >}}
363+
364+
<!--
365+
For details about etcd and its logs, view the [etcd documentation](https://etcd.io/docs/).
366+
Again, you can use Kubernetes' storage mechanisms to map persistent storage into
367+
the container that runs the component.
368+
-->
324369
有关 etcd 及其日志的详细信息,请查阅 [etcd 文档](https://etcd.io/docs/)
325370
同样,你可以使用 Kubernetes 的存储机制将持久存储映射到运行该组件的容器中。
326371

@@ -339,7 +384,7 @@ Some deploy tools account for that log rotation and automate it; others leave th
339384
as your responsibility.
340385
-->
341386
如果你部署 Kubernetes 集群组件(例如调度器)以将日志记录到从父节点共享的卷中,
342-
则需要考虑并确保这些日志被轮转。 **Kubernetes 不管理这种日志轮转**
387+
则需要考虑并确保这些日志被轮转。**Kubernetes 不管理这种日志轮转**
343388

344389
你的操作系统可能会自动实现一些日志轮转。例如,如果你将目录 `/var/log` 共享到一个组件的静态 Pod 中,
345390
则节点级日志轮转会将该目录中的文件视同为 Kubernetes 之外的组件所写入的文件。

‎content/zh-cn/docs/concepts/cluster-administration/system-logs.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ second line.}
207207
-->
208208
### 上下文日志 {#contextual-logging}
209209

210-
{{< feature-state for_k8s_version="v1.24" state="alpha" >}}
210+
{{< feature-state for_k8s_version="v1.30" state="beta" >}}
211211

212212
<!--
213213
Contextual logging builds on top of structured logging. It is primarily about
@@ -229,14 +229,16 @@ passed into functions by their caller.
229229
那么日志条目将会包含额外的信息,这些信息会被调用者传递给函数。
230230

231231
<!--
232-
Currently this is gated behind the `StructuredLogging` feature gate and
233-
disabled by default. The infrastructure for this was added in 1.24 without
232+
For Kubernetes {{< skew currentVersion >}}, this is gated behind the `ContextualLogging`
233+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) and is
234+
enabled by default. The infrastructure for this was added in 1.24 without
234235
modifying components. The
235236
[`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)
236237
command demonstrates how to use the new logging calls and how a component
237238
behaves that supports contextual logging.
238239
-->
239-
目前这一特性是由 `StructuredLogging` 特性门控所控制的,默认关闭。
240+
对于 Kubernetes {{< skew currentVersion >}},这一特性是由 `StructuredLogging`
241+
[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)所控制的,默认启用。
240242
这个基础设施是在 1.24 中被添加的,并不需要修改组件。
241243
[`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)
242244
命令演示了如何使用新的日志记录调用以及组件如何支持上下文日志记录。
@@ -248,23 +250,23 @@ $ go run . --help
248250
--feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:
249251
AllAlpha=true|false (ALPHA - default=false)
250252
AllBeta=true|false (BETA - default=false)
251-
ContextualLogging=true|false (ALPHA - default=false)
253+
ContextualLogging=true|false (BETA - default=true)
252254
$ go run . --feature-gates ContextualLogging=true
253255
...
254-
I0404 18:00:02.916429 451895 logger.go:94] "example/myname: runtime" foo="bar" duration="1m0s"
255-
I0404 18:00:02.916447 451895 logger.go:95] "example: another runtime" foo="bar" duration="1m0s"
256+
I0222 15:13:31.645988 197901 example.go:54] "runtime" logger="example.myname" foo="bar" duration="1m0s"
257+
I0222 15:13:31.646007 197901 example.go:55] "another runtime" logger="example" foo="bar" duration="1h0m0s" duration="1m0s"
256258
```
257259

258260
<!--
259-
The `example` prefix and `foo="bar"` were added by the caller of the function
261+
The `logger` key and `foo="bar"` were added by the caller of the function
260262
which logs the `runtime` message and `duration="1m0s"` value, without having to
261263
modify that function.
262264
263265
With contextual logging disable, `WithValues` and `WithName` do nothing and log
264266
calls go through the global klog logger. Therefore this additional information
265267
is not in the log output anymore:
266268
-->
267-
`example` 前缀和 `foo="bar"` 会被函数的调用者添加上,
269+
`logger` 键和 `foo="bar"` 会被函数的调用者添加上,
268270
不需修改该函数,它就会记录 `runtime` 消息和 `duration="1m0s"` 值。
269271

270272
禁用上下文日志后,`WithValues``WithName` 什么都不会做,
@@ -274,8 +276,8 @@ is not in the log output anymore:
274276
```console
275277
$ go run . --feature-gates ContextualLogging=false
276278
...
277-
I0404 18:03:31.171945 452150 logger.go:94] "runtime" duration="1m0s"
278-
I0404 18:03:31.171962 452150 logger.go:95] "another runtime" duration="1m0s"
279+
I0222 15:14:40.497333 198174 example.go:54] "runtime" duration="1m0s"
280+
I0222 15:14:40.497346 198174 example.go:55] "another runtime" duration="1h0m0s" duration="1m0s"
279281
```
280282

281283
<!--
@@ -406,8 +408,8 @@ To help with debugging issues on nodes, Kubernetes v1.27 introduced a feature th
406408
running on the node. To use the feature, ensure that the `NodeLogQuery`
407409
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled for that node, and that the
408410
kubelet configuration options `enableSystemLogHandler` and `enableSystemLogQuery` are both set to true. On Linux
409-
we assume that service logs are available via journald. On Windows we assume that service logs are available
410-
in the application log provider. On both operating systems, logs are also available by reading files within
411+
the assumption is that service logs are available via journald. On Windows the assumption is that service logs are
412+
available in the application log provider. On both operating systems, logs are also available by reading files within
411413
`/var/log/`.
412414
-->
413415
为了帮助在节点上调试问题,Kubernetes v1.27 引入了一个特性来查看节点上当前运行服务的日志。
@@ -419,15 +421,15 @@ in the application log provider. On both operating systems, logs are also availa
419421
在两种操作系统上,都可以通过读取 `/var/log/` 内的文件查看日志。
420422

421423
<!--
422-
Provided you are authorized to interact with node objects, you can try out this alpha feature on all your nodes or
424+
Provided you are authorized to interact with node objects, you can try out this feature on all your nodes or
423425
just a subset. Here is an example to retrieve the kubelet service logs from a node:
424426
425427
```shell
426428
# Fetch kubelet logs from a node named node-1.example
427429
kubectl get --raw "/api/v1/nodes/node-1.example/proxy/logs/?query=kubelet"
428430
```
429431
-->
430-
假如你被授权与节点对象交互,你可以在所有节点或只是某个子集上试用此 Alpha 特性
432+
假如你被授权与节点对象交互,你可以在所有节点或只是某个子集上试用此特性
431433
这里有一个从节点中检索 kubelet 服务日志的例子:
432434

433435
```shell
@@ -504,10 +506,12 @@ kubectl get --raw "/api/v1/nodes/node-1.example/proxy/logs/?query=kubelet&patter
504506
* Read about [Contextual Logging](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging)
505507
* Read about [deprecation of klog flags](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components)
506508
* Read about the [Conventions for logging severity](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md)
509+
* Read about [Log Query](https://kep.k8s.io/2258)
507510
-->
508511
* 阅读 [Kubernetes 日志架构](/zh-cn/docs/concepts/cluster-administration/logging/)
509512
* 阅读[结构化日志提案(英文)](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging)
510513
* 阅读[上下文日志提案(英文)](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging)
511514
* 阅读 [klog 参数的废弃(英文)](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components)
512515
* 阅读[日志严重级别约定(英文)](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md)
516+
* 阅读[日志查询](https://kep.k8s.io/2258)
513517

0 commit comments

Comments
 (0)