@@ -987,7 +987,7 @@ Pod 就会被从 {{< glossary_tooltip text="API 服务器" term_id="kube-apiserv
987
987
集群会从头开始重试,赋予 Pod 完整的体面终止限期。
988
988
989
989
<!--
990
- An example flow:
990
+ Pod termination flow, illustrated with an example :
991
991
992
992
1. You use the `kubectl` tool to manually delete a specific Pod, with the default grace period
993
993
(30 seconds).
@@ -999,7 +999,7 @@ An example flow:
999
999
as terminating (a graceful shutdown duration has been set), the kubelet begins the local Pod
1000
1000
shutdown process.
1001
1001
-->
1002
- 下面是一个例子 :
1002
+ Pod 终止流程,如下例所示 :
1003
1003
1004
1004
1 . 你使用 ` kubectl ` 工具手动删除某个特定的 Pod,而该 Pod 的体面终止限期是默认值(30 秒)。
1005
1005
@@ -1027,14 +1027,15 @@ An example flow:
1027
1027
1028
1028
如果 ` preStop ` 回调在体面期结束后仍在运行,kubelet 将请求短暂的、一次性的体面期延长 2 秒。
1029
1029
1030
- {{< note >}}
1031
- <!--
1032
- If the `preStop` hook needs longer to complete than the default grace period allows,
1033
- you must modify `terminationGracePeriodSeconds` to suit this.
1034
- -->
1035
- 如果 ` preStop ` 回调所需要的时间长于默认的体面终止限期,你必须修改
1036
- ` terminationGracePeriodSeconds ` 属性值来使其正常工作。
1037
- {{< /note >}}
1030
+ <!--
1031
+ If the `preStop` hook needs longer to complete than the default grace period allows,
1032
+ you must modify `terminationGracePeriodSeconds` to suit this.
1033
+ -->
1034
+
1035
+ {{< note >}}
1036
+ 如果 ` preStop ` 回调所需要的时间长于默认的体面终止限期,你必须修改
1037
+ ` terminationGracePeriodSeconds ` 属性值来使其正常工作。
1038
+ {{< /note >}}
1038
1039
1039
1040
<!--
1040
1041
1. The kubelet triggers the container runtime to send a TERM signal to process 1 inside each
@@ -1043,14 +1044,17 @@ An example flow:
1043
1044
1044
1045
2 . ` kubelet ` 接下来触发容器运行时发送 TERM 信号给每个容器中的进程 1。
1045
1046
1046
- {{< note >}}
1047
1047
<!--
1048
- The containers in the Pod receive the TERM signal at different times and in an arbitrary
1049
- order. If the order of shutdowns matters, consider using a `preStop` hook to synchronize.
1048
+ There is [special ordering](#termination-with-sidecars) if the Pod has any
1049
+ {{< glossary_tooltip text="sidecar containers" term_id="sidecar-container" >}} defined.
1050
+ Otherwise, the containers in the Pod receive the TERM signal at different times and in
1051
+ an arbitrary order. If the order of shutdowns matters, consider using a `preStop` hook
1052
+ to synchronize (or switch to using sidecar containers).
1050
1053
-->
1051
- Pod 中的容器会在不同时刻收到 TERM 信号,接收顺序也是不确定的。
1052
- 如果关闭的顺序很重要,可以考虑使用 ` preStop ` 回调逻辑来协调。
1053
- {{< /note >}}
1054
+
1055
+ 如果 Pod 中定义了{{< glossary_tooltip text="Sidecar 容器" term_id="sidecar-container" >}},
1056
+ 则存在[ 特殊排序] ( #termination-with-sidecars ) 。否则,Pod 中的容器会在不同的时间和任意的顺序接收
1057
+ TERM 信号。如果关闭顺序很重要,考虑使用 ` preStop ` 钩子进行同步(或者切换为使用 Sidecar 容器)。
1054
1058
1055
1059
<!--
1056
1060
1. At the same time as the kubelet is starting graceful shutdown of the Pod, the control plane
@@ -1097,74 +1101,31 @@ An example flow:
1097
1101
[ 探索 Pod 及其端点的终止行为] ( /zh-cn/docs/tutorials/services/pods-and-endpoint-termination-flow/ )
1098
1102
中找到有关如何实现连接排空的更多详细信息。
1099
1103
1100
- {{<note >}}
1101
- <!--
1102
- If you don't have the `EndpointSliceTerminatingCondition` feature gate enabled
1103
- in your cluster (the gate is on by default from Kubernetes 1.22, and locked to default in 1.26),
1104
- then the Kubernetes control plane removes a Pod from any relevant EndpointSlices as soon as the Pod's
1105
- termination grace period _begins_. The behavior above is described when the
1106
- feature gate `EndpointSliceTerminatingCondition` is enabled.
1107
- -->
1108
- 如果你的集群中没有启用 EndpointSliceTerminatingCondition 特性门控
1109
- (该门控从 Kubernetes 1.22 开始默认开启,在 1.26 中锁定为默认),
1110
- 那么一旦 Pod 的终止宽限期开始,Kubernetes 控制平面就会从所有的相关 EndpointSlices 中移除 Pod。
1111
- 上述行为是在 EndpointSliceTerminatingCondition 特性门控被启用时描述的。
1112
- {{</note >}}
1104
+ <a id =" pod-termination-beyond-grace-period " />
1113
1105
1114
- {{<note >}}
1115
1106
<!--
1116
- Beginning with Kubernetes 1.29, if your Pod includes one or more sidecar containers
1117
- (init containers with an Always restart policy), the kubelet will delay sending
1118
- the TERM signal to these sidecar containers until the last main container has fully terminated.
1119
- The sidecar containers will be terminated in the reverse order they are defined in the Pod spec.
1120
- This ensures that sidecar containers continue serving the other containers in the Pod until they are no longer needed.
1121
- -->
1122
- 从 Kubernetes 1.29 开始,如果你的 Pod 包含一个或多个 Sidecar
1123
- 容器(重启策略为 ` Always ` 的 Init 容器),kubelet 将延迟向这些
1124
- Sidecar 容器发送 TERM 信号,直到最后一个主容器完全终止。
1125
- Sidecar 容器将以 Pod 规约中定义的相反顺序终止。
1126
- 这可确保 Sidecar 容器继续为 Pod 中的其他容器提供服务,直到不再需要它们为止。
1127
-
1128
- <!--
1129
- Note that slow termination of a main container will also delay the termination of the sidecar containers.
1130
- If the grace period expires before the termination process is complete, the Pod may enter emergency termination.
1131
- In this case, all remaining containers in the Pod will be terminated simultaneously with a short grace period.
1132
- -->
1133
- 请注意,主容器的缓慢终止也会延迟边车容器的终止。
1134
- 如果宽限期在终止过程完成之前到期,Pod 可能会进入紧急终止状态。
1135
- 在这种情况下,Pod 中的所有剩余容器将在短暂的宽限期内同时终止。
1136
-
1137
- <!--
1138
- Similarly, if the Pod has a preStop hook that exceeds the termination grace period, emergency termination may occur.
1139
- In general, if you have used preStop hooks to control the termination order without sidecar containers, you can now
1140
- remove them and allow the kubelet to manage sidecar termination automatically.
1107
+ 1. The kubelet ensures the Pod is shut down and terminated
1108
+ 1. When the grace period expires, if there is still any container running in the Pod, the
1109
+ kubelet triggers forcible shutdown.
1110
+ The container runtime sends `SIGKILL` to any processes still running in any container in the Pod.
1111
+ The kubelet also cleans up a hidden `pause` container if that container runtime uses one.
1112
+ 1. The kubelet transitions the Pod into a terminal phase (`Failed` or `Succeeded` depending on
1113
+ the end state of its containers).
1114
+ 1. The kubelet triggers forcible removal of the Pod object from the API server, by setting grace period
1115
+ to 0 (immediate deletion).
1116
+ 1. The API server deletes the Pod's API object, which is then no longer visible from any client.
1141
1117
-->
1142
- 同样,如果 Pod 的 preStop 回调超过了终止宽限期,则可能会发生紧急终止。
1143
- 一般来说,如果你在没有 Sidecar 容器的情况下使用 preStop 回调来控制终止顺序,
1144
- 那么现在可以删除它们从而允许 kubelet 自动管理 Sidecar 终止。
1145
- {{</note >}}
1118
+ 4 . kubelet 确保 Pod 被关闭和终止
1146
1119
1147
- <!--
1148
- 1. When the grace period expires, the kubelet triggers forcible shutdown. The container runtime sends
1149
- `SIGKILL` to any processes still running in any container in the Pod.
1150
- The kubelet also cleans up a hidden `pause` container if that container runtime uses one.
1151
- 1. The kubelet transitions the Pod into a terminal phase (`Failed` or `Succeeded` depending on
1152
- the end state of its containers). This step is guaranteed since version 1.27.
1153
- 1. The kubelet triggers forcible removal of Pod object from the API server, by setting grace period
1154
- to 0 (immediate deletion).
1155
- 1. The API server deletes the Pod's API object, which is then no longer visible from any client.
1156
- -->
1157
- 1 . 超出终止宽限期限时,` kubelet ` 会触发强制关闭过程。容器运行时会向 Pod
1158
- 中所有容器内仍在运行的进程发送 ` SIGKILL ` 信号。
1159
- ` kubelet ` 也会清理隐藏的 ` pause ` 容器,如果容器运行时使用了这种容器的话。
1120
+ 1 . 超出终止宽限期限时,如果 Pod 中仍有容器在运行,kubelet 会触发强制关闭过程。
1121
+ 容器运行时会向 Pod 中所有容器内仍在运行的进程发送 ` SIGKILL ` 信号。
1122
+ ` kubelet ` 也会清理隐藏的 ` pause ` 容器,如果容器运行时使用了这种容器的话。
1160
1123
1161
- 1 . ` kubelet ` 将 Pod 转换到终止阶段(` Failed ` 或 ` Succeeded ` 具体取决于其容器的结束状态)。
1162
- 这一步从 1.27 版本开始得到保证。
1124
+ 1 . ` kubelet ` 将 Pod 转换到终止阶段(` Failed ` 或 ` Succeeded ` ,具体取决于其容器的结束状态)。
1163
1125
1164
- 1 . ` kubelet ` 触发强制从 API 服务器上删除 Pod 对象的逻辑,并将体面终止限期设置为 0
1165
- (这意味着马上删除)。
1126
+ 1 . kubelet 通过将宽限期设置为 0(立即删除),触发从 API 服务器强制移除 Pod 对象的操作。
1166
1127
1167
- 1 . API 服务器删除 Pod 的 API 对象,从任何客户端都无法再看到该对象。
1128
+ 1 . API 服务器删除 Pod 的 API 对象,从任何客户端都无法再看到该对象。
1168
1129
1169
1130
<!--
1170
1131
### Forced Pod termination {#pod-termination-forced}
@@ -1195,13 +1156,11 @@ begin immediate cleanup.
1195
1156
将宽限期限强制设置为 ` 0 ` 意味着立即从 API 服务器删除 Pod。
1196
1157
如果 Pod 仍然运行于某节点上,强制删除操作会触发 ` kubelet ` 立即执行清理操作。
1197
1158
1198
- {{< note >}}
1199
1159
<!--
1200
- You must specify an additional flag `--force` along with `--grace-period=0`
1160
+ Using kubectl, You must specify an additional flag `--force` along with `--grace-period=0`
1201
1161
in order to perform force deletions.
1202
1162
-->
1203
- 你必须在设置 ` --grace-period=0 ` 的同时额外设置 ` --force ` 参数才能发起强制删除请求。
1204
- {{< /note >}}
1163
+ 使用 kubectl 时,你必须在设置 ` --grace-period=0 ` 的同时额外设置 ` --force ` 参数才能发起强制删除请求。
1205
1164
1206
1165
<!--
1207
1166
When a force deletion is performed, the API server does not wait for confirmation
@@ -1231,6 +1190,41 @@ documentation for
1231
1190
如果你需要强制删除 StatefulSet 的 Pod,
1232
1191
请参阅[ 从 StatefulSet 中删除 Pod] ( /zh-cn/docs/tasks/run-application/force-delete-stateful-set-pod/ ) 的任务文档。
1233
1192
1193
+ <!--
1194
+ ### Pod shutdown and sidecar containers {##termination-with-sidecars}
1195
+
1196
+ If your Pod includes one or more
1197
+ [sidecar containers](/docs/concepts/workloads/pods/sidecar-containers/)
1198
+ (init containers with an Always restart policy), the kubelet will delay sending
1199
+ the TERM signal to these sidecar containers until the last main container has fully terminated.
1200
+ The sidecar containers will be terminated in the reverse order they are defined in the Pod spec.
1201
+ This ensures that sidecar containers continue serving the other containers in the Pod until they
1202
+ are no longer needed.
1203
+ -->
1204
+ ### Pod 关闭和 Sidecar 容器 {#termination-with-sidecars}
1205
+
1206
+ 如果你的 Pod 包含一个或多个 [ Sidecar 容器] ( /zh-cn/docs/concepts/workloads/pods/sidecar-containers/ )
1207
+ (重启策略为 Always 的 Init 容器),kubelet 将延迟向这些 Sidecar 容器发送 TERM 信号,
1208
+ 直到最后一个主容器已完全终止。Sidecar 容器将按照它们在 Pod 规约中被定义的相反顺序被终止。
1209
+ 这样确保了 Sidecar 容器继续为 Pod 中的其他容器提供服务,直到完全不再需要为止。
1210
+
1211
+ <!--
1212
+ This means that slow termination of a main container will also delay the termination of the sidecar containers.
1213
+ If the grace period expires before the termination process is complete, the Pod may enter [forced termination](#pod-termination-beyond-grace-period).
1214
+ In this case, all remaining containers in the Pod will be terminated simultaneously with a short grace period.
1215
+
1216
+ Similarly, if the Pod has a `preStop` hook that exceeds the termination grace period, emergency termination may occur.
1217
+ In general, if you have used `preStop` hooks to control the termination order without sidecar containers, you can now
1218
+ remove them and allow the kubelet to manage sidecar termination automatically.
1219
+ -->
1220
+ 这意味着主容器的慢终止也会延迟 Sidecar 容器的终止。
1221
+ 如果在终止过程完成之前宽限期已到,Pod 可能会进入[ 强制终止] ( #pod-termination-beyond-grace-period ) 阶段。
1222
+ 在这种情况下,Pod 中所有剩余的容器将在某个短宽限期内被同时终止。
1223
+
1224
+ 同样地,如果 Pod 有一个 ` preStop ` 钩子超过了终止宽限期,可能会发生紧急终止。
1225
+ 总体而言,如果你以前使用 ` preStop ` 钩子来控制没有 Sidecar 的 Pod 中容器的终止顺序,
1226
+ 你现在可以移除这些钩子,允许 kubelet 自动管理 Sidecar 的终止。
1227
+
1234
1228
<!--
1235
1229
### Garbage collection of Pods {#pod-garbage-collection}
1236
1230
0 commit comments