简体   繁体   中英

Node.js pod isn't getting the preStop lifecycle signal from Kubernetes

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM