Skip to content

Commit 345fcaa

Browse files
authored
Merge pull request #36849 from windsonsea/initcon
[zh]Sync /workloads/pods/init-containers.md
2 parents ee82265 + 9bdd7a8 commit 345fcaa

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

content/zh-cn/docs/concepts/workloads/pods/init-containers.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ A {{< glossary_tooltip text="Pod" term_id="pod" >}} can have multiple containers
3737
running apps within it, but it can also have one or more init containers, which are run
3838
before the app containers are started.
3939
-->
40-
## 理解 Init 容器
40+
## 理解 Init 容器 {#understanding-init-containers}
4141

4242
每个 {{< glossary_tooltip text="Pod" term_id="pod" >}} 中可以包含多个容器,
4343
应用运行在这些容器里面,同时 Pod 也可以有一个或多个先于应用容器启动的 Init 容器。
@@ -72,8 +72,8 @@ The status of the init containers is returned in `.status.initContainerStatuses`
7272
field as an array of the container statuses (similar to the `.status.containerStatuses`
7373
field).
7474
-->
75-
为 Pod 设置 Init 容器需要在 [Pod 规约](/zh-cn/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodSpec)
76-
中添加 `initContainers` 字段,
75+
为 Pod 设置 Init 容器需要在
76+
[Pod 规约](/zh-cn/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodSpec)中添加 `initContainers` 字段,
7777
该字段以 [Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core)
7878
类型对象数组的形式组织,和应用的 `containers` 数组同级相邻。
7979
参阅 API 参考的[容器](/zh-cn/docs/reference/kubernetes-api/workload-resources/pod-v1/#Container)章节了解详情。
@@ -97,7 +97,7 @@ container sequentially. Each init container must succeed before the next can run
9797
When all of the init containers have run to completion, kubelet initializes
9898
the application containers for the Pod and runs them as usual.
9999
-->
100-
### 与普通容器的不同之处
100+
### 与普通容器的不同之处 {#differences-from-regular-containers}
101101

102102
Init 容器支持应用容器的全部字段和特性,包括资源限制、数据卷和安全设置。
103103
然而,Init 容器对资源请求和限制的处理稍有不同,在下面[资源](#resources)节有说明。
@@ -120,35 +120,37 @@ have some advantages for start-up related code:
120120
`sed`, `awk`, `python`, or `dig` during setup.
121121
* The application image builder and deployer roles can work independently without
122122
the need to jointly build a single app image.
123-
* Init containers can run with a different view of the filesystem than app containers in the
124-
same Pod. Consequently, they can be given access to
125-
{{< glossary_tooltip text="Secrets" term_id="secret" >}} that app containers cannot access.
126-
* Because init containers run to completion before any app containers start, init containers offer
127-
a mechanism to block or delay app container startup until a set of preconditions are met. Once
128-
preconditions are met, all of the app containers in a Pod can start in parallel.
129-
* Init containers can securely run utilities or custom code that would otherwise make an app
130-
container image less secure. By keeping unnecessary tools separate you can limit the attack
131-
surface of your app container image.
132123
-->
133-
## 使用 Init 容器
124+
## 使用 Init 容器 {#using-init-containers}
134125

135126
因为 Init 容器具有与应用容器分离的单独镜像,其启动相关代码具有如下优势:
136127

137128
* Init 容器可以包含一些安装过程中应用容器中不存在的实用工具或个性化代码。
138129
例如,没有必要仅为了在安装过程中使用类似 `sed``awk``python``dig`
139130
这样的工具而去 `FROM` 一个镜像来生成一个新的镜像。
140131

141-
* Init 容器可以安全地运行这些工具,避免这些工具导致应用镜像的安全性降低。
142-
143132
* 应用镜像的创建者和部署者可以各自独立工作,而没有必要联合构建一个单独的应用镜像。
144133

145-
* Init 容器能以不同于 Pod 内应用容器的文件系统视图运行。因此,Init 容器可以访问
146-
应用容器不能访问的 {{< glossary_tooltip text="Secret" term_id="secret" >}} 的权限。
134+
<!--
135+
* Init containers can run with a different view of the filesystem than app containers in the
136+
same Pod. Consequently, they can be given access to
137+
{{< glossary_tooltip text="Secrets" term_id="secret" >}} that app containers cannot access.
138+
* Because init containers run to completion before any app containers start, init containers offer
139+
a mechanism to block or delay app container startup until a set of preconditions are met. Once
140+
preconditions are met, all of the app containers in a Pod can start in parallel.
141+
* Init containers can securely run utilities or custom code that would otherwise make an app
142+
container image less secure. By keeping unnecessary tools separate you can limit the attack
143+
surface of your app container image.
144+
-->
145+
* 与同一 Pod 中的多个应用容器相比,Init 容器能以不同的文件系统视图运行。因此,Init
146+
容器可以被赋予访问应用容器不能访问的 {{< glossary_tooltip text="Secret" term_id="secret" >}} 的权限。
147147

148148
* 由于 Init 容器必须在应用容器启动之前运行完成,因此 Init
149149
容器提供了一种机制来阻塞或延迟应用容器的启动,直到满足了一组先决条件。
150150
一旦前置条件满足,Pod 内的所有的应用容器会并行启动。
151151

152+
* Init 容器可以安全地运行实用程序或自定义代码,而在其他方式下运行这些实用程序或自定义代码可能会降低应用容器镜像的安全性。
153+
通过将不必要的工具分开,你可以限制应用容器镜像的被攻击范围。
152154
<!--
153155
### Examples
154156
@@ -205,10 +207,10 @@ This example defines a simple Pod that has two init containers.
205207
The first waits for `myservice`, and the second waits for `mydb`. Once both
206208
init containers complete, the Pod runs the app container from its `spec` section.
207209
-->
208-
### 使用 Init 容器的情况
210+
### 使用 Init 容器的情况 {#init-containers-in-use}
209211

210212
下面的例子定义了一个具有 2 个 Init 容器的简单 Pod。 第一个等待 `myservice` 启动,
211-
第二个等待 `mydb` 启动。 一旦这两个 Init容器 都启动完成,Pod 将启动 `spec` 节中的应用容器。
213+
第二个等待 `mydb` 启动。 一旦这两个 Init 容器都启动完成,Pod 将启动 `spec` 节中的应用容器。
212214

213215
```yaml
214216
apiVersion: v1
@@ -312,8 +314,8 @@ Events:
312314
16s 16s 1 {default-scheduler } Normal Scheduled Successfully assigned myapp-pod to 172.17.4.201
313315
16s 16s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Pulling pulling image "busybox"
314316
13s 13s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Pulled Successfully pulled image "busybox"
315-
13s 13s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Created Created container with docker id 5ced34a04634; Security:[seccomp=unconfined]
316-
13s 13s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Started Started container with docker id 5ced34a04634
317+
13s 13s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Created Created container init-myservice
318+
13s 13s 1 {kubelet 172.17.4.201} spec.initContainers{init-myservice} Normal Started Started container init-myservice
317319
```
318320

319321
<!--
@@ -367,10 +369,12 @@ To create the `mydb` and `myservice` services:
367369
```shell
368370
kubectl apply -f services.yaml
369371
```
372+
370373
<!--
371374
The output is similar to this:
372375
-->
373376
输出类似于:
377+
374378
```
375379
service/myservice created
376380
service/mydb created
@@ -388,7 +392,9 @@ kubectl get -f myapp.yaml
388392
<!--
389393
The output is similar to this:
390394
-->
395+
391396
输出类似于:
397+
392398
```
393399
NAME READY STATUS RESTARTS AGE
394400
myapp-pod 1/1 Running 0 9m
@@ -500,24 +506,21 @@ for resource usage apply:
500506
* The Pod's *effective request/limit* for a resource is the higher of:
501507
* the sum of all app containers request/limit for a resource
502508
* the effective init request/limit for a resource
509+
* Scheduling is done based on effective requests/limits, which means
510+
init containers can reserve resources for initialization that are not used
511+
during the life of the Pod.
512+
* The QoS (quality of service) tier of the Pod's *effective QoS tier* is the
513+
QoS tier for init containers and app containers alike.
503514
-->
504515
* 所有 Init 容器上定义的任何特定资源的 limit 或 request 的最大值,作为
505516
Pod **有效初始 request/limit**
506517
如果任何资源没有指定资源限制,这被视为最高限制。
507518
* Pod 对资源的 **有效 limit/request** 是如下两者中的较大者:
508519
* 所有应用容器对某个资源的 limit/request 之和
509520
* 对某个资源的有效初始 limit/request
510-
511-
<!--
512-
* Scheduling is done based on effective requests/limits, which means
513-
init containers can reserve resources for initialization that are not used
514-
during the life of the Pod.
515-
* The QoS (quality of service) tier of the Pod's *effective QoS tier* is the
516-
QoS tier for init containers and app containers alike.
517-
-->
518521
* 基于有效 limit/request 完成调度,这意味着 Init 容器能够为初始化过程预留资源,
519522
这些资源在 Pod 生命周期过程中并没有被使用。
520-
* Pod 的 **有效 QoS 层** ,与 Init 容器和应用容器的一样。
523+
* Pod 的 **有效 QoS 层**,与 Init 容器和应用容器的一样。
521524

522525
<!--
523526
Quota and limits are applied based on the effective Pod request and limit.

0 commit comments

Comments
 (0)