-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Graceful Pod Shutdown #3380
Comments
For node-based pods, use http-terminator import { createHttpTerminator } from "http-terminator";
const server = app.listen(argv.listenPort);
const httpTerminator = createHttpTerminator({
server
});
process.on("SIGTERM", () => {
console.log("SIGTERM signal received: closing HTTP server");
httpTerminator.terminate().then(() => {
console.log("HTTP server closed");
process.exit(0);
});
}); For scala / AKKA service, use Akka Coordinated Shutdown. val binding = Http().bindAndHandle(routes, "127.0.0.1", 8080)
shutdown.addTask(CoordinatedShutdown.PhaseServiceUnbind, "http-unbind") { () =>
binding.flatMap(_.unbind()).map(_ => Done)
}
shutdown.addTask(CoordinatedShutdown.PhaseServiceRequestsDone, "http-graceful-termination") { () =>
binding.flatMap(b =>
akka.pattern.after(10.seconds, system.scheduler)(b.terminate(15.seconds))
).map(_ => Done)
} Default AKKA CoordinatedShutdown setting is here |
closed via PR: #3392 |
The default
And in real life (notice that 25s is on a best-effort basis), more likely you only get 15s GracePeriod for your pod, see the logs below:
We will create a new ticket to make sure all pods (especially scala ones as they will wait for a few seconds for possible chunked response) can be graceful terminated within 15 seconds. |
Created a new ticket here: #3394 |
Support Graceful Pod Shutdown
The dev cluster uses preemptible nodes for cost saving. Because of it, most pods will be terminated at least once for every 24 hours.
When k8s terminates the nodes, the pod container will receive
SIGTERM
signal and is given 30s (default value of grace period) to gracefully exit (before anotherSIGKILL
was sent to the container for immediate exit).Our microservices should support the Graceful Pod Shutdown by recognising the
SIGTERM
signal and exiting voluntarily.Failing to do so will not cause any functionality impact. However, it might leave confusing "Error" status pods on the logs.
For node-based microservice, we can:
For scala-based (AKKA) microservice, see graceful termination of AKKA doc.
The text was updated successfully, but these errors were encountered: