How to catch preemption notice in NodeJs when running on a GKE cluster?

Viewed 285

I am running NodeJs services on a Google Kubernetes Cluster with Preemptible VM instances. Before such a VM shuts down a "preemption notice" is sent. (as described in the docs)

Compute Engine sends a preemption notice to the instance in the form of an ACPI G2 Soft Off signal

source


I want to know how to handle this signal from inside my NodeJs service?

Is it enough to do it like this?

process.on('SIGTERM', () => { 
  // do stuff to prepare service for shutdown
});
1 Answers

I'm afraid it's not enough, to make it works you need to add a shutdown script to your container.

In alternative you can install acpid in your container and listen its events through node-acpi.

Hope this helps.

Related