Skip to content

Commit bfea67a

Browse files
committed
Clarify PreStop hook behaviour
1 parent 2527359 commit bfea67a

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

content/en/docs/concepts/containers/container-lifecycle-hooks.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ No parameters are passed to the handler.
3636

3737
`PreStop`
3838

39-
This hook is called immediately before a container is terminated due to an API request or management event such as liveness probe failure, preemption, resource contention and others. A call to the preStop hook fails if the container is already in terminated or completed state.
40-
It is blocking, meaning it is synchronous,
41-
so it must complete before the signal to stop the container can be sent.
42-
No parameters are passed to the handler.
39+
This hook is called immediately before a container is terminated due to an API request or management
40+
event such as a liveness/startup probe failure, preemption, resource contention and others. This
41+
hook is not called if the container crashes or exits. The Pod's termination grace period countdown
42+
begins before the `PreStop` hook is executed. Regardless of the outcome of the handler, the
43+
container will eventually terminate within the Pod's termination grace period. No parameters are
44+
passed to the handler.
4345

4446
A more detailed description of the termination behavior can be found in
4547
[Termination of Pods](/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination).
@@ -65,19 +67,15 @@ the Container ENTRYPOINT and hook fire asynchronously.
6567
However, if the hook takes too long to run or hangs,
6668
the Container cannot reach a `running` state.
6769

68-
`PreStop` hooks are not executed asynchronously from the signal
69-
to stop the Container; the hook must complete its execution before
70-
the signal can be sent.
71-
If a `PreStop` hook hangs during execution,
72-
the Pod's phase will be `Terminating` and remain there until the Pod is
73-
killed after its `terminationGracePeriodSeconds` expires.
74-
This grace period applies to the total time it takes for both
75-
the `PreStop` hook to execute and for the Container to stop normally.
76-
If, for example, `terminationGracePeriodSeconds` is 60, and the hook
77-
takes 55 seconds to complete, and the Container takes 10 seconds to stop
78-
normally after receiving the signal, then the Container will be killed
79-
before it can stop normally, since `terminationGracePeriodSeconds` is
80-
less than the total time (55+10) it takes for these two things to happen.
70+
`PreStop` hooks are not executed asynchronously from the signal to stop the Container; the hook must
71+
complete its execution before the TERM signal can be sent. If a `PreStop` hook hangs during
72+
execution, the Pod's phase will be `Terminating` and remain there until the Pod is killed after its
73+
`terminationGracePeriodSeconds` expires. This grace period applies to the total time it takes for
74+
both the `PreStop` hook to execute and for the Container to stop normally. If, for example,
75+
`terminationGracePeriodSeconds` is 60, and the hook takes 55 seconds to complete, and the Container
76+
takes 10 seconds to stop normally after receiving the signal, then the Container will be killed
77+
before it can stop normally, since `terminationGracePeriodSeconds` is less than the total time
78+
(55+10) it takes for these two things to happen.
8179

8280
If either a `PostStart` or `PreStop` hook fails,
8381
it kills the Container.

0 commit comments

Comments
 (0)