I want to shutdown Node.js gracefully, but it doesn't receive the preStop signal from Kubernetes.
process.on('preStop', handleShutdown);
function handleShutdown() {
console.log("Pod will shut down in 30 seconds");
}
I current do not have a preStop lifecycle command in the .yaml because I couldn't find any way to get it to notify the Node.js worker
Thank you!
preStop
command will kill the container. Basically, it will kill your app process. If you set up only 'preStop', it does not work, unfortunately. Here is a sample POD, I played with minikube to test.
apiVersion: v1
kind: Pod
metadata:
name: lifecycle-demo
spec:
containers:
- name: lifecycle-demo-container
image: nginx
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
preStop:
exec:
command: ["/bin/sh", "-c", "/bin/sleep 120"]
terminationGracePeriodSeconds: 6000
I am telling to hold the kill for 120 second before killing it. If that does not happen, it will violently be killed after 6000 second.
For your case, terminationGracePeriodSeconds
itself should be enough.