@@ -511,7 +511,7 @@ processes, and the Pod is then deleted from the
511
511
container runtime's management service is restarted while waiting for processes to terminate, the
512
512
cluster retries from the start including the full original grace period.
513
513
514
- An example flow:
514
+ Pod termination flow, illustrated with an example :
515
515
516
516
1 . You use the ` kubectl ` tool to manually delete a specific Pod, with the default grace period
517
517
(30 seconds).
@@ -530,18 +530,19 @@ An example flow:
530
530
531
531
If the ` preStop ` hook is still running after the grace period expires, the kubelet requests
532
532
a small, one-off grace period extension of 2 seconds.
533
-
534
- {{< note >}}
535
- If the ` preStop ` hook needs longer to complete than the default grace period allows,
536
- you must modify ` terminationGracePeriodSeconds ` to suit this.
537
- {{< /note >}}
533
+ {{% note %}}
534
+ If the ` preStop ` hook needs longer to complete than the default grace period allows,
535
+ you must modify ` terminationGracePeriodSeconds ` to suit this.
536
+ {{% /note %}}
538
537
539
538
1 . The kubelet triggers the container runtime to send a TERM signal to process 1 inside each
540
539
container.
541
- {{< note >}}
542
- The containers in the Pod receive the TERM signal at different times and in an arbitrary
543
- order. If the order of shutdowns matters, consider using a ` preStop ` hook to synchronize.
544
- {{< /note >}}
540
+
541
+ There is [ special ordering] ( #termination-with-sidecars ) if the Pod has any
542
+ {{< glossary_tooltip text="sidecar containers" term_id="sidecar-container" >}} defined.
543
+ Otherwise, the containers in the Pod receive the TERM signal at different times and in
544
+ an arbitrary order. If the order of shutdowns matters, consider using a ` preStop ` hook
545
+ to synchronize (or switch to using sidecar containers).
545
546
546
547
1 . At the same time as the kubelet is starting graceful shutdown of the Pod, the control plane
547
548
evaluates whether to remove that shutting-down Pod from EndpointSlice (and Endpoints) objects,
@@ -565,38 +566,19 @@ An example flow:
565
566
condition ` serving ` . You can find more details on how to implement connections draining in the
566
567
tutorial [ Pods And Endpoints Termination Flow] ( /docs/tutorials/services/pods-and-endpoint-termination-flow/ )
567
568
568
- {{<note >}}
569
- If you don't have the ` EndpointSliceTerminatingCondition ` feature gate enabled
570
- in your cluster (the gate is on by default from Kubernetes 1.22, and locked to default in 1.26),
571
- then the Kubernetes control plane removes a Pod from any relevant EndpointSlices as soon as the Pod's
572
- termination grace period _ begins_ . The behavior above is described when the
573
- feature gate ` EndpointSliceTerminatingCondition ` is enabled.
574
- {{</note >}}
575
-
576
- {{<note >}}
577
- Beginning with Kubernetes 1.29, if your Pod includes one or more sidecar containers
578
- (init containers with an Always restart policy), the kubelet will delay sending
579
- the TERM signal to these sidecar containers until the last main container has fully terminated.
580
- The sidecar containers will be terminated in the reverse order they are defined in the Pod spec.
581
- This ensures that sidecar containers continue serving the other containers in the Pod until they are no longer needed.
582
-
583
- Note that slow termination of a main container will also delay the termination of the sidecar containers.
584
- If the grace period expires before the termination process is complete, the Pod may enter emergency termination.
585
- In this case, all remaining containers in the Pod will be terminated simultaneously with a short grace period.
569
+ <a id =" pod-termination-beyond-grace-period " />
586
570
587
- Similarly, if the Pod has a preStop hook that exceeds the termination grace period, emergency termination may occur.
588
- In general, if you have used preStop hooks to control the termination order without sidecar containers, you can now
589
- remove them and allow the kubelet to manage sidecar termination automatically.
590
- {{</note >}}
571
+ 1 . The kubelet ensures the Pod is shut down and terminated
572
+ 1 . When the grace period expires, if there is still any container running in the Pod, the
573
+ kubelet triggers forcible shutdown.
574
+ The container runtime sends ` SIGKILL ` to any processes still running in any container in the Pod.
575
+ The kubelet also cleans up a hidden ` pause ` container if that container runtime uses one.
576
+ 1 . The kubelet transitions the Pod into a terminal phase (` Failed ` or ` Succeeded ` depending on
577
+ the end state of its containers).
578
+ 1 . The kubelet triggers forcible removal of the Pod object from the API server, by setting grace period
579
+ to 0 (immediate deletion).
580
+ 1 . The API server deletes the Pod's API object, which is then no longer visible from any client.
591
581
592
- 1 . When the grace period expires, the kubelet triggers forcible shutdown. The container runtime sends
593
- ` SIGKILL ` to any processes still running in any container in the Pod.
594
- The kubelet also cleans up a hidden ` pause ` container if that container runtime uses one.
595
- 1 . The kubelet transitions the Pod into a terminal phase (` Failed ` or ` Succeeded ` depending on
596
- the end state of its containers). This step is guaranteed since version 1.27.
597
- 1 . The kubelet triggers forcible removal of Pod object from the API server, by setting grace period
598
- to 0 (immediate deletion).
599
- 1 . The API server deletes the Pod's API object, which is then no longer visible from any client.
600
582
601
583
### Forced Pod termination {#pod-termination-forced}
602
584
@@ -612,10 +594,8 @@ Setting the grace period to `0` forcibly and immediately deletes the Pod from th
612
594
server. If the Pod was still running on a node, that forcible deletion triggers the kubelet to
613
595
begin immediate cleanup.
614
596
615
- {{< note >}}
616
- You must specify an additional flag ` --force ` along with ` --grace-period=0 `
597
+ Using kubectl, You must specify an additional flag ` --force ` along with ` --grace-period=0 `
617
598
in order to perform force deletions.
618
- {{< /note >}}
619
599
620
600
When a force deletion is performed, the API server does not wait for confirmation
621
601
from the kubelet that the Pod has been terminated on the node it was running on. It
@@ -632,6 +612,24 @@ If you need to force-delete Pods that are part of a StatefulSet, refer to the ta
632
612
documentation for
633
613
[ deleting Pods from a StatefulSet] ( /docs/tasks/run-application/force-delete-stateful-set-pod/ ) .
634
614
615
+ ### Pod shutdown and sidecar containers {##termination-with-sidecars}
616
+
617
+ If your Pod includes one or more
618
+ [ sidecar containers] ( /docs/concepts/workloads/pods/sidecar-containers/ )
619
+ (init containers with an Always restart policy), the kubelet will delay sending
620
+ the TERM signal to these sidecar containers until the last main container has fully terminated.
621
+ The sidecar containers will be terminated in the reverse order they are defined in the Pod spec.
622
+ This ensures that sidecar containers continue serving the other containers in the Pod until they
623
+ are no longer needed.
624
+
625
+ This means that slow termination of a main container will also delay the termination of the sidecar containers.
626
+ If the grace period expires before the termination process is complete, the Pod may enter [ forced termination] ( #pod-termination-beyond-grace-period ) .
627
+ In this case, all remaining containers in the Pod will be terminated simultaneously with a short grace period.
628
+
629
+ Similarly, if the Pod has a ` preStop ` hook that exceeds the termination grace period, emergency termination may occur.
630
+ In general, if you have used ` preStop ` hooks to control the termination order without sidecar containers, you can now
631
+ remove them and allow the kubelet to manage sidecar termination automatically.
632
+
635
633
### Garbage collection of Pods {#pod-garbage-collection}
636
634
637
635
For failed Pods, the API objects remain in the cluster's API until a human or
0 commit comments