Graceful shutdown in Vetx Application

1/20/2021

Scaling down the Kubernetes pod is not closing the Vertx application(developed in java) gracefully. It basically kills the container.

Overridden the beforeStoppingVertx and afterStoppingVertx methods of io.vertx.core.Launcher class and printed some logs to verify Vertx is shutting down gracefully. When the pods are scaled down, the methods beforeStoppingVertx and afterStoppingVertx are never being invoked.

  @Override
  public void beforeStoppingVertx(Vertx vertx) {
    LOG.info("Vertx Closing Gracefully");
    vertx.close();
  }

  @Override
  public void afterStoppingVertx() {
    LOG.info("Vertx Closed Gracefully");
  }

Tried adding grace-period of 60 seconds to the deployments yml which is the common template, still it is of no use ( beforeStoppingVertx and afterStoppingVertx methods not invoked even after 60 secs)

My suspicion is that vert.x is never getting told to shut down. Or it's not getting the message. We do have options to define Pre Stop hooks in Kubernetes, https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination

The question is what is the actual script, that we need to mention as part of the Pre-stop hook, that would instruct the Vert.x to shutdown gracefully ?

-- Subhasis Dash
application-shutdown
graceful-shutdown
kubernetes
kubernetes-pod
vert.x

0 Answers