Skip to content

Commit 0ae7021

Browse files
authored
Merge pull request #35637 from windsonsea/hookyhf
[zh-cn] updated /containers/container-lifecycle-hooks.md
2 parents 3fa68c0 + 8243456 commit 0ae7021

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

content/zh-cn/docs/concepts/containers/container-lifecycle-hooks.md

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ and run code implemented in a handler when the corresponding lifecycle hook is e
4141
4242
There are two hooks that are exposed to Containers:
4343
-->
44-
## 容器回调
44+
## 容器回调 {#container-hooks}
4545

4646
有两个回调暴露给容器:
4747

@@ -80,7 +80,7 @@ A more detailed description of the termination behavior can be found in
8080
[Termination of Pods](/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination).
8181
-->
8282
有关终止行为的更详细描述,请参见
83-
[终止 Pod](/zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#termination-of-pods)
83+
[终止 Pod](/zh-cn/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination)
8484

8585
<!--
8686
### Hook handler implementations
@@ -99,7 +99,7 @@ Resources consumed by the command are counted against the Container.
9999
* HTTP - Executes an HTTP request against a specific endpoint on the Container.
100100
-->
101101

102-
* Exec - 在容器的 cgroups 和名称空间中执行特定的命令(例如 `pre-stop.sh`)。
102+
* Exec - 在容器的 cgroups 和名字空间中执行特定的命令(例如 `pre-stop.sh`)。
103103
命令所消耗的资源计入容器的资源消耗。
104104
* HTTP - 对容器上的特定端点执行 HTTP 请求。
105105

@@ -140,31 +140,14 @@ takes 55 seconds to complete, and the Container takes 10 seconds to stop
140140
normally after receiving the signal, then the Container will be killed
141141
before it can stop normally, since `terminationGracePeriodSeconds` is
142142
less than the total time (55+10) it takes for these two things to happen.
143-
144-
`PreStop` hooks are not executed asynchronously from the signal
145-
to stop the Container; the hook must complete its execution before
146-
the signal can be sent.
147-
If a `PreStop` hook hangs during execution,
148-
the Pod's phase will be `Terminating` and remain there until the Pod is
149-
killed after its `terminationGracePeriodSeconds` expires.
150-
This grace period applies to the total time it takes for both
151-
the `PreStop` hook to execute and for the Container to stop normally.
152-
If, for example, `terminationGracePeriodSeconds` is 60, and the hook
153-
takes 55 seconds to complete, and the Container takes 10 seconds to stop
154-
normally after receiving the signal, then the Container will be killed
155-
before it can stop normally, since `terminationGracePeriodSeconds` is
156-
less than the total time (55+10) it takes for these two things to happen.
157143
-->
158-
`PreStop` 回调并不会与停止容器的信号处理程序异步执行;回调必须在
159-
可以发送信号之前完成执行。
160-
如果 `PreStop` 回调在执行期间停滞不前,Pod 的阶段会变成 `Terminating`
161-
并且一直处于该状态,直到其 `terminationGracePeriodSeconds` 耗尽为止,
162-
这时 Pod 会被杀死。
144+
`PreStop` 回调并不会与停止容器的信号处理程序异步执行;回调必须在可以发送信号之前完成执行。
145+
如果 `PreStop` 回调在执行期间停滞不前,Pod 的阶段会变成 `Terminating`并且一直处于该状态,
146+
直到其 `terminationGracePeriodSeconds` 耗尽为止,这时 Pod 会被杀死。
163147
这一宽限期是针对 `PreStop` 回调的执行时间及容器正常停止时间的总和而言的。
164-
例如,如果 `terminationGracePeriodSeconds` 是 60,回调函数花了 55 秒钟
165-
完成执行,而容器在收到信号之后花了 10 秒钟来正常结束,那么容器会在其
166-
能够正常结束之前即被杀死,因为 `terminationGracePeriodSeconds` 的值
167-
小于后面两件事情所花费的总时间(55+10)。
148+
例如,如果 `terminationGracePeriodSeconds` 是 60,回调函数花了 55 秒钟完成执行,
149+
而容器在收到信号之后花了 10 秒钟来正常结束,那么容器会在其能够正常结束之前即被杀死,
150+
因为 `terminationGracePeriodSeconds` 的值小于后面两件事情所花费的总时间(55+10)。
168151

169152
<!--
170153
If either a `PostStart` or `PreStop` hook fails,
@@ -224,7 +207,7 @@ Here is some example output of the resulting events you see from running `kubect
224207
对于 `PostStart`,这是 `FailedPostStartHook` 事件,对于 `PreStop`,这是 `FailedPreStopHook` 事件。
225208
要自己生成失败的 `FailedPreStopHook` 事件,请修改
226209
[lifecycle-events.yaml](https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/lifecycle-events.yaml)
227-
文件将 postStart 命令更改为 ”badcommand“ 并应用它。
210+
文件将 postStart 命令更改为 “badcommand” 并应用它。
228211
以下是通过运行 `kubectl describe pod lifecycle-demo` 后你看到的一些结果事件的示例输出:
229212

230213
```
@@ -250,6 +233,6 @@ Events:
250233
[attaching handlers to Container lifecycle events](/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/).
251234
-->
252235

253-
* 进一步了解[容器环境](/zh-cn/docs/concepts/containers/container-environment/)
254-
* 动手实践,[为容器生命周期事件添加处理程序](/zh-cn/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/)
236+
* 进一步了解[容器环境](/zh-cn/docs/concepts/containers/container-environment/)
237+
* 动手[为容器的生命周期事件设置处理函数](/zh-cn/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/)
255238

0 commit comments

Comments
 (0)