How to handle K8s preStop hook in ASP.NET Core?

4/3/2020

In k8s documentation it says:

Containers can access a hook by implementing and registering a handler for that hook. There are two types of hook handlers that can be implemented for Containers:

Exec - Executes a specific command, such as pre-stop.sh, inside the cgroups and namespaces of the Container. Resources consumed by the command are counted against the Container.

HTTP - Executes an HTTP request against a specific endpoint on the Container.

I am concerned about how can we handle this hook through an HTTP request in .NET Core. I couldn't find any examples in the documentation or anywhere else on the web.

What I want to achieve is that once K8s executes this hook I want to start reporting Unhealthy through my Readiness checks so that K8s doesn't send more traffic to the pod before it sends the SIGTERM signal.

What do you guys think about how can we handle this hook in a .NET Core application?

-- Sameed
asp.net-core
kubernetes
kubernetes-health-check

0 Answers