Skip to content

Commit 2f24422

Browse files
committed
[zh-cn]sync logging counter-pod-err.yaml apiserver-audit.v1
Signed-off-by: xin.li <[email protected]>
1 parent 44ae714 commit 2f24422

File tree

3 files changed

+83
-21
lines changed

3 files changed

+83
-21
lines changed

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

+63-12
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,57 @@ appending a container name to the command, with a `-c` flag, like so:
122122
kubectl logs counter -c count
123123
```
124124

125+
<!--
126+
### Container log streams
127+
-->
128+
### 容器日志流 {#container-log-streams}
129+
130+
{{< feature-state feature_gate_name="PodLogsQuerySplitStreams" >}}
131+
132+
<!--
133+
As an alpha feature, the kubelet can split out the logs from the two standard streams produced
134+
by a container: [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout))
135+
and [standard error](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).
136+
To use this behavior, you must enable the `PodLogsQuerySplitStreams`
137+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/).
138+
With that feature gate enabled, Kubernetes {{< skew currentVersion >}} allows access to these
139+
log streams directly via the Pod API. You can fetch a specific stream by specifying the stream name (either `Stdout` or `Stderr`),
140+
using the `stream` query string. You must have access to read the `log` subresource of that Pod.
141+
-->
142+
作为一种 Alpha 特性,kubelet 可以将容器产生的两个标准流的日志分开:
143+
[标准输出](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout))
144+
[标准错误](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr))输出。
145+
要使用此行为,你必须启用 `PodLogsQuerySplitStreams`
146+
[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
147+
启用该特性门控后,Kubernetes {{< skew currentVersion >}} 允许通过 Pod API 直接访问这些日志流。
148+
你可以通过指定流名称(`Stdout``Stderr`)使用 `stream` 查询字符串来获取特定的流。
149+
你必须具有读取该 Pod 的 `log` 子资源的权限。
150+
151+
<!--
152+
To demonstrate this feature, you can create a Pod that periodically writes text to both the standard output and error stream.
153+
-->
154+
要演示此特性,你可以创建一个定期向标准输出和标准错误流中写入文本的 Pod。
155+
156+
{{% code_sample file="debug/counter-pod-err.yaml" %}}
157+
158+
<!--
159+
To run this pod, use the following command:
160+
-->
161+
要运行此 Pod,使用以下命令:
162+
163+
```shell
164+
kubectl apply -f https://k8s.io/examples/debug/counter-pod-err.yaml
165+
```
166+
167+
<!--
168+
To fetch only the stderr log stream, you can run:
169+
-->
170+
要仅获取 stderr 日志流,你可以运行以下命令:
171+
172+
```shell
173+
kubectl get --raw "/api/v1/namespaces/default/pods/counter-err/log?stream=Stderr"
174+
```
175+
125176
<!--
126177
See the [`kubectl logs` documentation](/docs/reference/generated/kubectl/kubectl-commands#logs)
127178
for more details.
@@ -161,7 +212,7 @@ kubelet 通过 Kubernetes API 的特殊功能将日志提供给客户端访问
161212
<!--
162213
### Log rotation
163214
-->
164-
### 日志轮转 {#log-rotation}
215+
### 日志轮换 {#log-rotation}
165216

166217
{{< feature-state for_k8s_version="v1.21" state="stable" >}}
167218

@@ -218,7 +269,7 @@ after 10 MiB, running `kubectl logs` returns at most 10MiB of data.
218269
-->
219270
只有最新的日志文件的内容可以通过 `kubectl logs` 获得。
220271

221-
例如,如果 Pod 写入 40 MiB 的日志,并且 kubelet 在 10 MiB 之后轮转日志
272+
例如,如果 Pod 写入 40 MiB 的日志,并且 kubelet 在 10 MiB 之后轮换日志
222273
则运行 `kubectl logs` 将最多返回 10 MiB 的数据。
223274
{{< /note >}}
224275

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

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

392-
一些部署工具会考虑日志轮转并将其自动化;而其他一些工具会将此留给你来处理。
443+
一些部署工具会考虑日志轮换并将其自动化;而其他一些工具会将此留给你来处理。
393444
{{< /note >}}
394445

395446
<!--
@@ -588,9 +639,9 @@ the application itself. An example of this approach is a small container running
588639
However, it's more straightforward to use `stdout` and `stderr` directly, and
589640
leave rotation and retention policies to the kubelet.
590641
-->
591-
边车容器还可用于轮转应用程序本身无法轮转的日志文件
642+
边车容器还可用于轮换应用程序本身无法轮换的日志文件
592643
这种方法的一个例子是定期运行 `logrotate` 的小容器。
593-
但是,直接使用 `stdout``stderr` 更直接,而将轮转和保留策略留给 kubelet。
644+
但是,直接使用 `stdout``stderr` 更直接,而将轮换和保留策略留给 kubelet。
594645

595646
<!--
596647
The node-level agent installed in your cluster picks up those log streams
@@ -619,9 +670,9 @@ rotated by the application itself. An example of this approach is a small contai
619670
However, it's recommended to use `stdout` and `stderr` directly and leave rotation
620671
and retention policies to the kubelet.
621672
-->
622-
如果应用程序本身不能轮转日志文件,则可以通过边车容器实现。
623-
这种方式的一个例子是运行一个小的、定期轮转日志的容器
624-
然而,还是推荐直接使用 `stdout``stderr`将日志的轮转和保留策略交给 kubelet。
673+
如果应用程序本身不能轮换日志文件,则可以通过边车容器实现。
674+
这种方式的一个例子是运行一个小的、定期轮换日志的容器
675+
然而,还是推荐直接使用 `stdout``stderr`将日志的轮换和保留策略交给 kubelet。
625676

626677
<!--
627678
#### Sidecar container with a logging agent
@@ -675,7 +726,7 @@ The second manifest describes a pod that has a sidecar container running fluentd
675726
The pod mounts a volume where fluentd can pick up its configuration data.
676727
-->
677728
第二个清单描述了一个运行 fluentd 边车容器的 Pod。
678-
该 Pod 挂载一个卷,flutend 可以从这个卷上拣选其配置数据。
729+
该 Pod 挂载一个卷,fluentd 可以从这个卷上拣选其配置数据。
679730

680731
{{% code_sample file="admin/logging/two-files-counter-pod-agent-sidecar.yaml" %}}
681732

content/zh-cn/docs/reference/config-api/apiserver-audit.v1.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Event 结构包含可出现在 API 审计日志中的所有信息。
111111
</tr>
112112

113113
<tr><td><code>user</code> <B><!--[Required]-->[必需]</B><br/>
114-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#userinfo-v1-authentication-k8s-io"><code>authentication/v1.UserInfo</code></a>
114+
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#userinfo-v1-authentication-k8s-io"><code>authentication/v1.UserInfo</code></a>
115115
</td>
116116
<td>
117117
<p>
@@ -124,7 +124,7 @@ Event 结构包含可出现在 API 审计日志中的所有信息。
124124
</tr>
125125

126126
<tr><td><code>impersonatedUser</code><br/>
127-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#userinfo-v1-authentication-k8s-io"><code>authentication/v1.UserInfo</code></a>
127+
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#userinfo-v1-authentication-k8s-io"><code>authentication/v1.UserInfo</code></a>
128128
</td>
129129
<td>
130130
<p>
@@ -204,7 +204,7 @@ Note: All but the last IP can be arbitrarily set by the client.
204204
</tr>
205205

206206
<tr><td><code>responseStatus</code><br/>
207-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#status-v1-meta"><code>meta/v1.Status</code></a>
207+
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#status-v1-meta"><code>meta/v1.Status</code></a>
208208
</td>
209209
<td>
210210
<p>
@@ -257,7 +257,7 @@ Note: All but the last IP can be arbitrarily set by the client.
257257
</tr>
258258

259259
<tr><td><code>requestReceivedTimestamp</code><br/>
260-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#microtime-v1-meta"><code>meta/v1.MicroTime</code></a>
260+
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#microtime-v1-meta"><code>meta/v1.MicroTime</code></a>
261261
</td>
262262
<td>
263263
<!--
@@ -270,7 +270,7 @@ Note: All but the last IP can be arbitrarily set by the client.
270270
</tr>
271271

272272
<tr><td><code>stageTimestamp</code><br/>
273-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#microtime-v1-meta"><code>meta/v1.MicroTime</code></a>
273+
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#microtime-v1-meta"><code>meta/v1.MicroTime</code></a>
274274
</td>
275275
<td>
276276
<p>
@@ -326,7 +326,7 @@ EventList 是审计事件(Event)的列表。
326326
<tr><td><code>kind</code><br/>string</td><td><code>EventList</code></td></tr>
327327

328328
<tr><td><code>metadata</code><br/>
329-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#listmeta-v1-meta"><code>meta/v1.ListMeta</code></a>
329+
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#listmeta-v1-meta"><code>meta/v1.ListMeta</code></a>
330330
</td>
331331
<td>
332332
<span class="text-muted"><!--No description provided.-->列表结构元数据</span>
@@ -368,7 +368,7 @@ Policy 定义的是审计日志的配置以及不同类型请求的日志记录
368368
<tr><td><code>kind</code><br/>string</td><td><code>Policy</code></td></tr>
369369

370370
<tr><td><code>metadata</code><br/>
371-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#objectmeta-v1-meta"><code>meta/v1.ObjectMeta</code></a>
371+
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#objectmeta-v1-meta"><code>meta/v1.ObjectMeta</code></a>
372372
</td>
373373
<td>
374374
<p>
@@ -458,7 +458,7 @@ PolicyList 是由审计策略(Policy)组成的列表。
458458
<tr><td><code>kind</code><br/>string</td><td><code>PolicyList</code></td></tr>
459459

460460
<tr><td><code>metadata</code><br/>
461-
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#listmeta-v1-meta"><code>meta/v1.ListMeta</code></a>
461+
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#listmeta-v1-meta"><code>meta/v1.ListMeta</code></a>
462462
</td>
463463
<td>
464464
<span class="text-muted"><!--No description provided.-->列表结构元数据。</span>
@@ -810,7 +810,8 @@ PolicyRule 包含一个映射,基于元数据将请求映射到某审计级别
810810
<p>
811811
<code>nonResourceURLs</code> 是一组需要被审计的 URL 路径。
812812
允许使用 <code>&ast;<code>,但只能作为路径中最后一个完整分段。
813-
例如:</p>
813+
例如:
814+
</p>
814815
<ul>
815816
<li>&quot;/metrics&quot; - 记录对 API 服务器度量值(metrics)的所有请求;</li>
816817
<li>&quot;/healthz&ast;&quot; - 记录所有健康检查。</li>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: counter-err
5+
spec:
6+
containers:
7+
- name: count
8+
image: busybox:1.28
9+
args: [/bin/sh, -c,
10+
'i=0; while true; do echo "$i: $(date)"; echo "$i: err" >&2 ; i=$((i+1)); sleep 1; done']

0 commit comments

Comments
 (0)