kubernetes: GracefulNodeShutdown does not trigger on nodes shutdown with `shutdown -h now`
What happened?
Shutting down a node with shutdown -h now does not trigger the graceful node drain.
Despite being indicated in the original proposal https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/2000-graceful-node-shutdown
In the context of this KEP, shutdown is referred to as shutdown of the underlying machine. On most linux distros shutdown can be initiated via a variety of methods for example:
- shutdown -h now
- shutdown -h +30 #schedule a delayed shutdown in 30mins
and explained in the blog: https://kubernetes.io/blog/2021/04/21/graceful-node-shutdown-beta/
How does it work? On Linux, your system can shut down in many different situations. For example:
- A user or script running shutdown -h now or systemctl poweroff or systemctl reboot.
the command seems to not behave the same way as sending a PrepareForShutdown signal on the dbus.
The node does not drain itself from its pods and pods will stay Running until timeout and it becomes stuck at Terminating
On the other hand, shutdown -h now acts similarly as a forced shutdown and as I understand, a forced shutdown on a node doesn’t allow a grace period as it is forced; so one can argue that there is nothing wrong with the behavior. However, the need to clarify the documentation on what counts as a shutdown that can trigger GracefulNodeShutdown may be helpful.
What did you expect to happen?
Expecting a similar behavior as if executing
# systemctl poweroff
or
#dbus-send --system /org/freedesktop/login1 org.freedesktop.login1.Manager.PrepareForShutdown boolean:true
where the graceful node drain occurs and terminates the pods.
How can we reproduce it (as minimally and precisely as possible)?
- Start a cluster with kubeadm init with this config. I use 2 worker nodes by default but can be reproduced with 1.
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
networking:
podSubnet: "10.244.0.0/16" #flannel
controlPlaneEndpoint: "XXX.XXX.XXX.XXX"
---
apiVersion: kubelet.config.k8s.io/v1beta1
cgroupDriver: systemd
featureGates:
GracefulNodeShutdown: true
shutdownGracePeriod: 90s
shutdownGracePeriodCriticalPods: 30s
kind: KubeletConfiguration
-
Make a deployment or a statefulset; I used this statefulset config in my environment: https://github.com/kubernetes/kubernetes/issues/118310#issuecomment-1698823460
-
Monitor the pods on a terminal logged SSHed the control plane:
kubectl get pods --watch
- On a terminal logged in a worker node, execute shutdown with the following command:
shutdown -h now
Anything else we need to know?
No response
Kubernetes version
tested on kubernetes versions 1.26, 1.27, 1.28, 1.29
Cloud provider
N/A
OS version
# On Linux:
$ cat /etc/os-release
NAME="CentOS Stream"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Stream 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream"
$ uname -a
Linux localhost.localdomain 4.18.0-544.el8.x86_64 #1 SMP Thu Feb 22 21:29:23 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, …) and versions (if applicable)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 28 (13 by maintainers)
Thanks.
@tuibeovince, no worries. The process here is like any other change. See for example:
Make sure to add the original authors, etc.
Additional supporting information, I also checked the StatefulSet and Deployment pod behaviors on a cluster in a Centos 9 Stream environment with systemd 255 using kubernetes 1.29.0 and the GracefulNodeShutdown works as expected, with
shutdown -h nowworking as if I executedsystemctl poweroff.