Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes readiness/liveness probe in console app

I have a console app in .net core. How to implement Kubernetes readiness/liveness probe?

My app process rabbitmq messages in loop, and don`t listen any http ports.

like image 481
RouR Avatar asked Dec 17 '17 18:12

RouR


People also ask

How do you check readiness probe in Kubernetes?

There is no separate endpoint for readiness probes, but we can access events using the kubectl describe pods <POD_NAME> command, for example, to get the current status. Use kubectl get pods command to see the pods' status. Pods and their status and ready states will be displayed, our pod is running as expected.

How do you test liveness and readiness probes?

Step 1 - Deploy a multi-node Kubernetes cluster. Step 2 - Deploy the Gremlin Kubernetes agent. Step 3 - Deploy an application with a liveness probe configured. Step 4 - Run a Latency experiment to validate your liveness probe configuration.

What is difference between readiness and liveness probe in Kubernetes?

Readiness probes are configured similarly to liveness probes. The only difference is that you use the readinessProbe field instead of the livenessProbe field. Configuration for HTTP and TCP readiness probes also remains identical to liveness probes.


3 Answers

Readiness probe makes zero sense for this scenario as you will not direct any traffic via means of Service. As your app reads rabbitmq on it's own, it will do so regardless of kube probes. There is logic though in using liveness probe where you might want to restart container if the process inside has failed in some way.

You can either create a status api endpoint which will listen on some port for http requests and respond with 200 OK if your application is healthy (you need some logic inside to define what healthy means) or use command based probe to launch a command that will do some checking and report if container is ok or not.

like image 23
Radek 'Goblin' Pieczonka Avatar answered Sep 22 '22 10:09

Radek 'Goblin' Pieczonka


In this case, it may be better to create a sidecar container in the same pod. This container would host an ASP.NET Core site, specifically to leverage the new health checks api recently introduced in .NET Core 2.2. There are extensions for monitoring rabbitmq connectivity. You would then expose the ASP.NET Core website for health checks.

ASP.NET Core Health Montioring

AspNetCore.HealthChecks.Rabbitmq

like image 63
rifferte Avatar answered Sep 24 '22 10:09

rifferte


Here are some nice solutions to add health check to non-asp application (console application for example):

Performing a health check in .NET Core Worker Service

I would suggest to implement the TCP solution, as it is minimal but still gives the expected result.

like image 43
Yair Maron Avatar answered Sep 25 '22 10:09

Yair Maron