Document Kubernetes' preStop sleep

Closes gh-43830
This commit is contained in:
Moritz Halbritter 2025-01-30 10:22:25 +01:00
parent 817f466c12
commit 7f9b4c6ff6
1 changed files with 18 additions and 1 deletions

View File

@ -124,7 +124,22 @@ Because this shutdown processing happens in parallel (and due to the nature of d
You can configure a sleep execution in a preStop handler to avoid requests being routed to a pod that has already begun shutting down.
This sleep should be long enough for new requests to stop being routed to the pod and its duration will vary from deployment to deployment.
The preStop handler can be configured by using the PodSpec in the pod's configuration file as follows:
If you're using Kubernetes 1.32 or up, the preStop handler can be configured by using the PodSpec in the pod's configuration file as follows:
[source,yaml]
----
spec:
containers:
- name: "example-container"
image: "example-image"
lifecycle:
preStop:
sleep:
seconds: 10
----
If you're not on Kubernetes 1.32 yet, you can use an `exec` command to invoke `sleep`.
[source,yaml]
----
@ -138,6 +153,8 @@ spec:
command: ["sh", "-c", "sleep 10"]
----
NOTE: The container needs to have a shell for this to work.
Once the pre-stop hook has completed, SIGTERM will be sent to the container and xref:reference:web/graceful-shutdown.adoc[graceful shutdown] will begin, allowing any remaining in-flight requests to complete.
NOTE: When Kubernetes sends a SIGTERM signal to the pod, it waits for a specified time called the termination grace period (the default for which is 30 seconds).