Skip to content

Commit 8637bc9

Browse files
authored
Merge pull request #26350 from dippynark/clarify-pre-stop-hook-description
Clarify PreStop hook behaviour
2 parents c036f87 + cbf7a63 commit 8637bc9

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ 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. A call
41+
to the `PreStop` hook fails if the container is already in a terminated or completed state and the
42+
hook must complete before the TERM signal to stop the container can be sent. The Pod's termination
43+
grace period countdown begins before the `PreStop` hook is executed, so regardless of the outcome of
44+
the handler, the container will eventually terminate within the Pod's termination grace period. No
45+
parameters are passed to the handler.
4346

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

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

8281
If either a `PostStart` or `PreStop` hook fails,
8382
it kills the Container.

0 commit comments

Comments
 (0)