@@ -28,6 +28,14 @@ array (which describes app containers).
28
28
你可以在 Pod 的规约中与用来描述应用容器的 ` containers ` 数组平行的位置指定
29
29
Init 容器。
30
30
31
+ <!--
32
+ In Kubernetes, a [sidecar container](/docs/concepts/workloads/pods/sidecar-containers/) is a container that
33
+ starts before the main application container and _continues to run_. This document is about init containers:
34
+ containers that run to completion during Pod initialization.
35
+ -->
36
+ 在 Kubernetes 中,[ 边车容器] ( /zh-cn/docs/concepts/workloads/pods/sidecar-containers/ )
37
+ 是在主应用容器之前启动并** 持续运行** 的容器。本文介绍 Init 容器:在 Pod 初始化期间完成运行的容器。
38
+
31
39
<!-- body -->
32
40
33
41
<!--
@@ -88,14 +96,6 @@ Init containers support all the fields and features of app containers,
88
96
including resource limits, [volumes](/docs/concepts/storage/volumes/), and security settings. However, the
89
97
resource requests and limits for an init container are handled differently,
90
98
as documented in [Resource sharing within containers](#resource-sharing-within-containers).
91
-
92
- Also, init containers do not support `lifecycle`, `livenessProbe`, `readinessProbe`, or
93
- `startupProbe` because they must run to completion before the Pod can be ready.
94
-
95
- If you specify multiple init containers for a Pod, kubelet runs each init
96
- container sequentially. Each init container must succeed before the next can run.
97
- When all of the init containers have run to completion, kubelet initializes
98
- the application containers for the Pod and runs them as usual.
99
99
-->
100
100
### 与普通容器的不同之处 {#differences-from-regular-containers}
101
101
@@ -104,13 +104,60 @@ Init 容器支持应用容器的全部字段和特性,包括资源限制、
104
104
然而,Init 容器对资源请求和限制的处理稍有不同,
105
105
在下面[ 容器内的资源共享] ( #resource-sharing-within-containers ) 节有说明。
106
106
107
- 同时 Init 容器不支持 ` lifecycle ` 、` livenessProbe ` 、` readinessProbe ` 和 ` startupProbe ` ,
108
- 因为它们必须在 Pod 就绪之前运行完成。
107
+ <!--
108
+ Regular init containers (in other words: excluding sidecar containers) do not support the
109
+ `lifecycle`, `livenessProbe`, `readinessProbe`, or `startupProbe` fields. Init containers
110
+ must run to completion before the Pod can be ready; sidecar containers continue running
111
+ during a Pod's lifetime, and _do_ support some probes. See [sidecar container](/docs/concepts/workloads/pods/sidecar-containers/)
112
+ for further details about sidecar containers.
113
+ -->
114
+ 常规的 Init 容器(即不包括边车容器)不支持 ` lifecycle ` 、` livenessProbe ` 、` readinessProbe ` 或
115
+ ` startupProbe ` 字段。Init 容器必须在 Pod 准备就绪之前完成运行;而边车容器在 Pod 的生命周期内继续运行,
116
+ 它支持一些探针。有关边车容器的细节请参阅[ 边车容器] ( /zh-cn/docs/concepts/workloads/pods/sidecar-containers/ ) 。
109
117
118
+ <!--
119
+ If you specify multiple init containers for a Pod, kubelet runs each init
120
+ container sequentially. Each init container must succeed before the next can run.
121
+ When all of the init containers have run to completion, kubelet initializes
122
+ the application containers for the Pod and runs them as usual.
123
+ -->
110
124
如果为一个 Pod 指定了多个 Init 容器,这些容器会按顺序逐个运行。
111
125
每个 Init 容器必须运行成功,下一个才能够运行。当所有的 Init 容器运行完成时,
112
126
Kubernetes 才会为 Pod 初始化应用容器并像平常一样运行。
113
127
128
+ <!--
129
+ ### Differences from sidecar containers
130
+
131
+ Init containers run and complete their tasks before the main application container starts.
132
+ Unlike [sidecar containers](/docs/concepts/workloads/pods/sidecar-containers),
133
+ init containers are not continuously running alongside the main containers.
134
+ -->
135
+ ### 与边车容器的不同之处 {#differences-from-sidecar-containers}
136
+
137
+ Init 容器在主应用容器启动之前运行并完成其任务。
138
+ 与[ 边车容器] ( /zh-cn/docs/concepts/workloads/pods/sidecar-containers ) 不同,
139
+ Init 容器不会持续与主容器一起运行。
140
+
141
+ <!--
142
+ Init containers run to completion sequentially, and the main container does not start
143
+ until all the init containers have successfully completed.
144
+
145
+ init containers do not support `lifecycle`, `livenessProbe`, `readinessProbe`, or
146
+ `startupProbe` whereas sidecar containers support all these [probes](/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe) to control their lifecycle.
147
+ -->
148
+ Init 容器按顺序完成运行,等到所有 Init 容器成功完成之后,主容器才会启动。
149
+
150
+ Init 容器不支持 ` lifecycle ` 、` livenessProbe ` 、` readinessProbe ` 或 ` startupProbe ` ,
151
+ 而边车容器支持所有这些[ 探针] ( /zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe ) 以控制其生命周期。
152
+
153
+ <!--
154
+ Init containers share the same resources (CPU, memory, network) with the main application
155
+ containers but do not interact directly with them. They can, however, use shared volumes
156
+ for data exchange.
157
+ -->
158
+ Init 容器与主应用容器共享资源(CPU、内存、网络),但不直接与主应用容器进行交互。
159
+ 不过这些容器可以使用共享卷进行数据交换。
160
+
114
161
<!--
115
162
## Using init containers
116
163
@@ -492,90 +539,15 @@ Init 容器一直重复失败。
492
539
在 Pod 中的每个应用容器和 Init 容器的名称必须唯一;
493
540
与任何其它容器共享同一个名称,会在校验时抛出错误。
494
541
495
- <!--
496
- #### API for sidecar containers
497
- -->
498
- #### 边车容器 API {#api-for-sidecar-containers}
499
-
500
- {{< feature-state for_k8s_version="v1.28" state="alpha" >}}
501
-
502
- <!--
503
- Starting with Kubernetes 1.28 in alpha, a feature gate named `SidecarContainers`
504
- allows you to specify a `restartPolicy` for init containers which is independent of
505
- the Pod and other init containers. Container [probes](/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe)
506
- can also be added to control their lifecycle.
507
- -->
508
- Kubernetes 自 1.28 版本起引入了一个名为 ` SidecarContainers ` 的 Alpha 特性门控,
509
- 允许你为 Init 容器指定独立于 Pod 和其他 Init 容器的 ` restartPolicy ` 。
510
- 你还可以添加容器[ 探针] ( /zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe ) 来控制
511
- Init 容器的生命周期。
512
-
513
- <!--
514
- If an init container is created with its `restartPolicy` set to `Always`, it will
515
- start and remain running during the entire life of the Pod, which is useful for
516
- running supporting services separated from the main application containers.
517
-
518
- If a `readinessProbe` is specified for this init container, its result will be used
519
- to determine the `ready` state of the Pod.
520
- -->
521
- 如果 Init 容器被创建时 ` restartPolicy ` 设置为 ` Always ` ,则 Init 容器将启动并在整个 Pod
522
- 的生命期内保持运行,这对于运行与主应用容器分离的支持服务非常有用。
523
-
524
- 如果为该 Init 容器指定了 ` readinessProbe ` ,则其结果将用于确定 Pod 的 ` ready ` 状态。
525
-
526
- <!--
527
- Since these containers are defined as init containers, they benefit from the same
528
- ordering and sequential guarantees as other init containers, allowing them to
529
- be mixed with other init containers into complex Pod initialization flows.
530
-
531
- Compared to regular init containers, sidecar-style init containers continue to
532
- run and the next init container can begin starting once the kubelet has set
533
- the `started` container status for the sidecar-style init container to true.
534
- That status either becomes true because there is a process running in the
535
- container and no startup probe defined, or
536
- as a result of its `startupProbe` succeeding.
537
- -->
538
- 由于这些容器以 Init 容器的形式定义,所以它们具有与其他 Init 容器相同的按序执行和顺序保证优势,
539
- 从而允许使用这些容器与其他 Init 容器混合在一起构造复杂的 Pod 初始化流程。
540
-
541
- 与常规的 Init 容器相比,只要 kubelet 将边车风格的 Init 容器的 ` started ` 容器状态设置为 true,
542
- 边车风格的 Init 容器会继续运行,下一个 Init 容器可以开始启动。
543
- 到达该状态的前提是,要么需要容器中有进程正在运行且未定义启动探针,要么其 ` startupProbe ` 的结果是成功的。
544
-
545
- <!--
546
- This feature can be used to implement the sidecar container pattern in a more
547
- robust way, as the kubelet always restarts a sidecar container if it fails.
548
-
549
- Here's an example of a Deployment with two containers, one of which is a sidecar:
550
- -->
551
- 此特性可用于以更稳健的方式实现边车容器模式,这是因为如果某个边车容器失败,kubelet 总会重新启动它。
552
-
553
- 以下是一个具有两个容器的 Deployment 示例,其中一个是边车:
554
-
555
- {{% code_sample language="yaml" file="application/deployment-sidecar.yaml" %}}
556
-
557
- <!--
558
- This feature is also useful for running Jobs with sidecars, as the sidecar
559
- container will not prevent the Job from completing after the main container
560
- has finished.
561
-
562
- Here's an example of a Job with two containers, one of which is a sidecar:
563
- -->
564
- 此特性也可用于运行带有边车的 Job,因为在主容器完成后,边车容器不会阻止 Job 完成。
565
-
566
- 以下是一个具有两个容器的 Job 示例,其中一个是边车:
567
-
568
- {{% code_sample language="yaml" file="application/job/job-sidecar.yaml" %}}
569
-
570
542
<!--
571
543
#### Resource sharing within containers
572
544
573
- Given the ordering and execution for init containers, the following rules
545
+ Given the order of execution for init, sidecar and app containers, the following rules
574
546
for resource usage apply:
575
547
-->
576
548
#### 容器内的资源共享 {#resource-sharing-within-containers}
577
549
578
- 在给定的 Init 容器执行顺序下 ,资源使用适用于如下规则:
550
+ 在给定的 Init、边车和应用容器执行顺序下 ,资源使用适用于如下规则:
579
551
580
552
<!--
581
553
* The highest of any particular resource request or limit defined on all init
@@ -601,11 +573,15 @@ for resource usage apply:
601
573
* Pod 的 ** 有效 QoS 层** ,与 Init 容器和应用容器的一样。
602
574
603
575
<!--
604
- Quota and limits are applied based on the effective Pod request and limit.
605
- Pod level control groups (cgroups) are based on the effective Pod request and limit, the same as the scheduler.
576
+ Quota and limits are applied based on the effective Pod request and
577
+ limit.
578
+
579
+ Pod level control groups (cgroups) are based on the effective Pod request and
580
+ limit, the same as the scheduler.
606
581
-->
607
582
配额和限制适用于有效 Pod 的请求和限制值。
608
- Pod 级别的 cgroups 是基于有效 Pod 的请求和限制值,和调度器相同。
583
+
584
+ Pod 级别的控制组(Cgroup)是基于 Pod 的有效 request 和 limit,与调度器相同。
609
585
610
586
<!--
611
587
### Pod restart reasons
@@ -617,6 +593,15 @@ reasons:
617
593
618
594
Pod 重启会导致 Init 容器重新执行,主要有如下几个原因:
619
595
596
+ {{< comment >}}
597
+ <!--
598
+ This section also present under [sidecar containers](/docs/concepts/workloads/pods/sidecar-containers/) page.
599
+ If you're editing this section, change both places.
600
+ -->
601
+ 这部分内容也出现在[ 边车容器] ( /zh-cn/docs/concepts/workloads/pods/sidecar-containers/ ) 页面上。
602
+ 如果你正在编辑这部分内容,请同时修改两处。
603
+ {{< /comment >}}
604
+
620
605
<!--
621
606
* The Pod infrastructure container is restarted. This is uncommon and would
622
607
have to be done by someone with root access to nodes.
@@ -644,14 +629,19 @@ Pod 不会被重启。这一行为适用于 Kubernetes v1.20 及更新版本。
644
629
## {{% heading "whatsnext" %}}
645
630
646
631
<!--
647
- * Read about [creating a Pod that has an init container](/docs/tasks/configure-pod-container/configure-pod-initialization/#create-a-pod-that-has-an-init-container)
648
- * Learn how to [debug init containers](/docs/tasks/debug/debug-application/debug-init-containers/)
649
- * Read about an overview of [kubelet](/docs/reference/command-line-tools-reference/kubelet/) and [kubectl](/docs/reference/kubectl/)
650
- * Learn about the [types of probes](/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe): liveness, readiness, startup probe.
632
+ Learn more about the following:
633
+ * [Creating a Pod that has an init container](/docs/tasks/configure-pod-container/configure-pod-initialization/#create-a-pod-that-has-an-init-container).
634
+ * [Debug init containers](/docs/tasks/debug/debug-application/debug-init-containers/).
635
+ * Overview of [kubelet](/docs/reference/command-line-tools-reference/kubelet/) and [kubectl](/docs/reference/kubectl/).
636
+ * [Types of probes](/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe): liveness, readiness, startup probe.
637
+ * [Sidecar containers](/docs/concepts/workloads/pods/sidecar-containers).
651
638
-->
652
- * 阅读[ 创建包含 Init 容器的 Pod] ( /zh-cn/docs/tasks/configure-pod-container/configure-pod-initialization/#create-a-pod-that-has-an-init-container )
653
- * 学习如何[ 调试 Init 容器] ( /zh-cn/docs/tasks/debug/debug-application/debug-init-containers/ )
654
- * 阅读 [ kubelet] ( /zh-cn/docs/reference/command-line-tools-reference/kubelet/ ) 和
639
+ 进一步了解以下内容:
640
+
641
+ * [ 创建包含 Init 容器的 Pod] ( /zh-cn/docs/tasks/configure-pod-container/configure-pod-initialization/#create-a-pod-that-has-an-init-container )
642
+ * [ 调试 Init 容器] ( /zh-cn/docs/tasks/debug/debug-application/debug-init-containers/ )
643
+ * [ kubelet] ( /zh-cn/docs/reference/command-line-tools-reference/kubelet/ ) 和
655
644
[ kubectl] ( /zh-cn/docs/reference/kubectl/ ) 的概述。
656
- * 了解探针的 [ 类型 ] ( /zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe ) :
645
+ * [ 探针类型 ] ( /zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#types-of-probe ) :
657
646
存活态探针、就绪态探针、启动探针。
647
+ * [ 边车容器] ( /zh-cn/docs/concepts/workloads/pods/sidecar-containers ) 。
0 commit comments