@@ -20,22 +20,23 @@ that runs temporarily in an existing {{< glossary_tooltip term_id="pod" >}} to
20
20
accomplish user-initiated actions such as troubleshooting. You use ephemeral
21
21
containers to inspect services rather than to build applications.
22
22
-->
23
- 本页面概述了临时容器:一种特殊的容器,该容器在现有 {{< glossary_tooltip text="Pod" term_id="pod" >}}
23
+ 本页面概述了临时容器:一种特殊的容器,该容器在现有
24
+ {{< glossary_tooltip text="Pod" term_id="pod" >}}
24
25
中临时运行,以便完成用户发起的操作,例如故障排查。
25
26
你会使用临时容器来检查服务,而不是用它来构建应用程序。
26
27
28
+ {{< warning >}}
27
29
<!--
28
30
Ephemeral containers are in early alpha state and are not suitable for production
29
31
clusters. You should expect the feature not to work in some situations, such as
30
32
when targeting the namespaces of a container. In accordance with the [Kubernetes
31
33
Deprecation Policy](/docs/reference/using-api/deprecation-policy/), this alpha
32
34
feature could change significantly in the future or be removed entirely.
33
35
-->
34
- {{< warning >}}
35
- 临时容器处于早期的 alpha 阶段,不适用于生产环境集群。
36
+ 临时容器处于早期的 Alpha 阶段,不适用于生产环境集群。
36
37
应该预料到临时容器在某些情况下不起作用,例如在定位容器的命名空间时。
37
38
根据 [ Kubernetes 弃用政策] ( /zh/docs/reference/using-api/deprecation-policy/ ) ,
38
- 此 alpha 功能将来可能发生重大变化或被完全删除。
39
+ 此 Alpha 功能将来可能发生重大变化或被完全删除。
39
40
{{< /warning >}}
40
41
41
42
<!-- body -->
@@ -49,7 +50,7 @@ replaceable, you cannot add a container to a Pod once it has been created.
49
50
Instead, you usually delete and replace Pods in a controlled fashion using
50
51
{{< glossary_tooltip text="deployments" term_id="deployment" >}}.
51
52
-->
52
- ## 了解临时容器
53
+ ## 了解临时容器 {#understanding-ephemeral-containers}
53
54
54
55
{{< glossary_tooltip text="Pod" term_id="pod" >}} 是 Kubernetes 应用程序的基本构建块。
55
56
由于 Pod 是一次性且可替换的,因此一旦 Pod 创建,就无法将容器加入到 Pod 中。
@@ -74,7 +75,7 @@ they are not appropriate for building applications. Ephemeral containers are
74
75
described using the same `ContainerSpec` as regular containers, but many fields
75
76
are incompatible and disallowed for ephemeral containers.
76
77
-->
77
- ### 什么是临时容器?
78
+ ### 什么是临时容器? {#what-is-an-ephemeral-container}
78
79
79
80
临时容器与其他容器的不同之处在于,它们缺少对资源或执行的保证,并且永远不会自动重启,
80
81
因此不适用于构建应用程序。
@@ -89,9 +90,7 @@ are incompatible and disallowed for ephemeral containers.
89
90
-->
90
91
- 临时容器没有端口配置,因此像 ` ports ` ,` livenessProbe ` ,` readinessProbe `
91
92
这样的字段是不允许的。
92
-
93
93
- Pod 资源分配是不可变的,因此 ` resources ` 配置是不允许的。
94
-
95
94
- 有关允许字段的完整列表,请参见
96
95
[ EphemeralContainer 参考文档] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#ephemeralcontainer-v1-core)。
97
96
@@ -116,7 +115,7 @@ Ephemeral containers are useful for interactive troubleshooting when `kubectl
116
115
exec` is insufficient because a container has crashed or a container image
117
116
doesn't include debugging utilities.
118
117
-->
119
- ## 临时容器的用途
118
+ ## 临时容器的用途 {#uses-for-ephemeral-containers}
120
119
121
120
当由于容器崩溃或容器镜像不包含调试工具而导致 ` kubectl exec ` 无用时,
122
121
临时容器对于交互式故障排查很有用。
@@ -128,7 +127,7 @@ and exposure to bugs and vulnerabilities. Since distroless images do not include
128
127
shell or any debugging utilities, it's difficult to troubleshoot distroless
129
128
images using `kubectl exec` alone.
130
129
-->
131
- 尤其是,[ distroless 镜像] ( https://github.com/GoogleContainerTools/distroless )
130
+ 尤其是,[ Distroless 镜像] ( https://github.com/GoogleContainerTools/distroless )
132
131
允许用户部署最小的容器镜像,从而减少攻击面并减少故障和漏洞的暴露。
133
132
由于 distroless 镜像不包含 Shell 或任何的调试工具,因此很难单独使用
134
133
` kubectl exec ` 命令进行故障排查。
@@ -138,19 +137,28 @@ When using ephemeral containers, it's helpful to enable [process namespace
138
137
sharing](/docs/tasks/configure-pod-container/share-process-namespace/) so
139
138
you can view processes in other containers.
140
139
-->
141
- 使用临时容器时,启用[ 进程名字空间共享] ( /zh/docs/tasks/configure-pod-container/share-process-namespace/ )
140
+ 使用临时容器时,启用
141
+ [ 进程名字空间共享] ( /zh/docs/tasks/configure-pod-container/share-process-namespace/ )
142
142
很有帮助,可以查看其他容器中的进程。
143
143
144
144
<!--
145
- ### Examples
145
+ See [Debugging with Ephemeral Debug Container](/docs/tasks/debug-application-cluster/debug-running-pod/#ephemeral-container)
146
+ for examples of troubleshooting using ephemeral containers.
147
+ -->
148
+ 关于如何使用临时容器来执行故障排查的例子,可参阅
149
+ [ 使用临时调试容器来调试] ( /zh/docs/tasks/debug-application-cluster/debug-running-pod/#ephemeral-container ) 。
146
150
151
+ <!--
152
+ ## Ephemeral containers API
153
+ -->
154
+ ### 临时容器 API {#ephemeral-containers-api}」
155
+
156
+ {{< note >}}
157
+ <!--
147
158
The examples in this section require the `EphemeralContainers` [feature
148
159
gate](/docs/reference/command-line-tools-reference/feature-gates/) to be
149
160
enabled, and Kubernetes client and server version v1.16 or later.
150
161
-->
151
- ### 示例
152
-
153
- {{< note >}}
154
162
本节中的示例要求启用 ` EphemeralContainers `
155
163
[ 特性门控] ( /zh/docs/reference/command-line-tools-reference/feature-gates/ ) ,
156
164
并且 kubernetes 客户端和服务端版本要求为 v1.16 或更高版本。
@@ -180,7 +188,7 @@ the ephemeral container to add as an `EphemeralContainers` list:
180
188
"apiVersion" : " v1" ,
181
189
"kind" : " EphemeralContainers" ,
182
190
"metadata" : {
183
- "name" : " example-pod"
191
+ "name" : " example-pod"
184
192
},
185
193
"ephemeralContainers" : [{
186
194
"command" : [
@@ -281,34 +289,3 @@ You can attach to the new ephemeral container using `kubectl attach`:
281
289
kubectl attach -it example-pod -c debugger
282
290
```
283
291
284
- <!--
285
- If process namespace sharing is enabled, you can see processes from all the containers in that Pod.
286
- For example, after attaching, you run `ps` in the debugger container:
287
- -->
288
- 如果启用了进程命名空间共享,则可以查看该 Pod 所有容器中的进程。
289
- 例如,运行上述 ` attach ` 操作后,在调试器容器中运行 ` ps ` 操作:
290
-
291
- ``` shell
292
- # 在 "debugger" 临时容器内中运行此 shell 命令
293
- ps auxww
294
- ```
295
-
296
- 运行命令后,输出类似于:
297
-
298
- ```
299
- PID USER TIME COMMAND
300
- 1 root 0:00 /pause
301
- 6 root 0:00 nginx: master process nginx -g daemon off;
302
- 11 101 0:00 nginx: worker process
303
- 12 101 0:00 nginx: worker process
304
- 13 101 0:00 nginx: worker process
305
- 14 101 0:00 nginx: worker process
306
- 15 101 0:00 nginx: worker process
307
- 16 101 0:00 nginx: worker process
308
- 17 101 0:00 nginx: worker process
309
- 18 101 0:00 nginx: worker process
310
- 19 root 0:00 /pause
311
- 24 root 0:00 sh
312
- 29 root 0:00 ps auxww
313
- ```
314
-
0 commit comments