Skip to content

Commit fea3a58

Browse files
KEP 4960: Container Stop Signals (#49857)
* Placeholder docs PR for KEP 4960: Container Stop Signals * Added note in pod termination page * Added stop signal section in pod termination docs * Update pod-lifecycle.md --------- Co-authored-by: Qiming Teng <[email protected]>
1 parent eca7cd3 commit fea3a58

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ parameters are passed to the handler.
4747
A more detailed description of the termination behavior can be found in
4848
[Termination of Pods](/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination).
4949

50+
`StopSignal`
51+
52+
The StopSignal lifecycle can be used to define a stop signal which would be sent to the container when it is
53+
stopped. If you set this, it overrides any `STOPSIGNAL` instruction defined within the container image.
54+
55+
A more detailed description of termination behaviour with custom stop signals can be found in
56+
[Stop Signals](/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination-stop-signals).
57+
5058
### Hook handler implementations
5159

5260
Containers can access a hook by implementing and registering a handler for that hook.

content/en/docs/concepts/workloads/pods/pod-lifecycle.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ Value | Description
113113

114114
{{< note >}}
115115

116-
When a pod is failing to start repeatedly, `CrashLoopBackOff` may appear in the `Status` field of some kubectl commands. Similarly, when a pod is being deleted, `Terminating` may appear in the `Status` field of some kubectl commands.
116+
When a pod is failing to start repeatedly, `CrashLoopBackOff` may appear in the `Status` field of some kubectl commands.
117+
Similarly, when a pod is being deleted, `Terminating` may appear in the `Status` field of some kubectl commands.
117118

118119
Make sure not to confuse _Status_, a kubectl display field for user intuition, with the pod's `phase`.
119120
Pod phase is an explicit part of the Kubernetes data model and of the
@@ -453,9 +454,14 @@ Each probe must define exactly one of these four mechanisms:
453454
the port is open. If the remote system (the container) closes
454455
the connection immediately after it opens, this counts as healthy.
455456

456-
{{< caution >}} Unlike the other mechanisms, `exec` probe's implementation involves the creation/forking of multiple processes each time when executed.
457-
As a result, in case of the clusters having higher pod densities, lower intervals of `initialDelaySeconds`, `periodSeconds`, configuring any probe with exec mechanism might introduce an overhead on the cpu usage of the node.
458-
In such scenarios, consider using the alternative probe mechanisms to avoid the overhead.{{< /caution >}}
457+
{{< caution >}}
458+
Unlike the other mechanisms, `exec` probe's implementation involves
459+
the creation/forking of multiple processes each time when executed.
460+
As a result, in case of the clusters having higher pod densities,
461+
lower intervals of `initialDelaySeconds`, `periodSeconds`,
462+
configuring any probe with exec mechanism might introduce an overhead on the cpu usage of the node.
463+
In such scenarios, consider using the alternative probe mechanisms to avoid the overhead.
464+
{{< /caution >}}
459465

460466
### Probe outcome
461467

@@ -569,13 +575,53 @@ before the Pod is allowed to be forcefully killed. With that forceful shutdown t
569575
place, the {{< glossary_tooltip text="kubelet" term_id="kubelet" >}} attempts graceful
570576
shutdown.
571577

572-
Typically, with this graceful termination of the pod, kubelet makes requests to the container runtime to attempt to stop the containers in the pod by first sending a TERM (aka. SIGTERM) signal, with a grace period timeout, to the main process in each container. The requests to stop the containers are processed by the container runtime asynchronously. There is no guarantee to the order of processing for these requests. Many container runtimes respect the `STOPSIGNAL` value defined in the container image and, if different, send the container image configured STOPSIGNAL instead of TERM.
578+
Typically, with this graceful termination of the pod, kubelet makes requests to the container runtime
579+
to attempt to stop the containers in the pod by first sending a TERM (aka. SIGTERM) signal,
580+
with a grace period timeout, to the main process in each container.
581+
The requests to stop the containers are processed by the container runtime asynchronously.
582+
There is no guarantee to the order of processing for these requests.
583+
Many container runtimes respect the `STOPSIGNAL` value defined in the container image and,
584+
if different, send the container image configured STOPSIGNAL instead of TERM.
573585
Once the grace period has expired, the KILL signal is sent to any remaining
574586
processes, and the Pod is then deleted from the
575587
{{< glossary_tooltip text="API Server" term_id="kube-apiserver" >}}. If the kubelet or the
576588
container runtime's management service is restarted while waiting for processes to terminate, the
577589
cluster retries from the start including the full original grace period.
578590

591+
### Stop Signals {#pod-termination-stop-signals}
592+
593+
The stop signal used to kill the container can be defined in the container image with the `STOPSIGNAL` instruction.
594+
If no stop signal is defined in the image, the default signal of the container runtime
595+
(SIGTERM for both containerd and CRI-O) would be used to kill the container.
596+
597+
### Defining custom stop signals
598+
599+
{{< feature-state feature_gate_name="ContainerStopSignals" >}}
600+
601+
If the `ContainerStopSignals` feature gate is enabled, you can configure a custom stop signal
602+
for your containers from the container Lifecycle. We require the Pod's `spec.os.name` field
603+
to be present as a requirement for defining stop signals in the container lifecycle.
604+
The list of signals that are valid depends on the OS the Pod is scheduled to.
605+
For Pods scheduled to Windows nodes, we only support SIGTERM and SIGKILL as valid signals.
606+
607+
Here is an example Pod spec defining a custom stop signal:
608+
609+
```yaml
610+
spec:
611+
os:
612+
name: linux
613+
containers:
614+
- name: my-container
615+
image: container-image:latest
616+
lifecycle:
617+
stopSignal: SIGUSR1
618+
```
619+
620+
If a stop signal is defined in the lifecycle, this will override the signal defined in the container image.
621+
If no stop signal is defined in the container spec, the container would fall back to the default behavior.
622+
623+
### Pod Termination Flow {#pod-termination-flow}
624+
579625
Pod termination flow, illustrated with an example:
580626

581627
1. You use the `kubectl` tool to manually delete a specific Pod, with the default grace period
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: ContainerStopSignals
3+
content_type: feature_gate
4+
_build:
5+
list: never
6+
render: false
7+
8+
stages:
9+
- stage: alpha
10+
defaultValue: false
11+
fromVersion: "1.33"
12+
---
13+
Enables usage of the StopSignal lifecycle for containers for configuring custom stop signals using which the containers would be stopped.

0 commit comments

Comments
 (0)