I have a simple consol application I want there is rabbitmq connection as a consumer and there is a database connection to SQL Server.
Before Containarize the application. There is some commands I have implemented, For example if I enterned X the application will exit so internaly I stop the consumer first and make sure there is no pending message and then gracefully I exit the application.
After Containarize the application I did successfully containarize the application and working perfectly under kuberenetes cluster but my problem is that How to send command to my application ?
For example I want to implement Livenessprob: check the database connection
Before terminating the pod I want to write x to my running console to implement gracefully exit the application without messages loss.
postStart:
exec:
command: []
preStop:
exec:
command: []
I expecting the solution to be a specific command which is writing to my running console application But how to send that command? Or how to make my console able to receive commands from kubernetes?
In Kubernetes, you can set up Liveness, Readiness, and Startup Probes. Check the official Kubernetes Documentation page on this topic.
The Kubelet Node agent can perform these probes on running Pods using 3 different methods:
/health
), and succeeds if the response status is between 200 and 399If you wish you can define a liveness probe command:
To perform a probe, the kubelet executes the command
cat /tmp/healthy
in the target container. If the command succeeds, it returns 0, and the kubelet considers the container to be alive and healthy. If the command returns a non-zero value, the kubelet kills the container and restarts it.Container Lifecycle Hooks (docs)
There are two types of hook handlers that can be implemented for Containers:
Example:
And as you mentioned in comments you can use the
touch /someDir/someFile
preStop command to create a file and watch it in your app to shutdown gracefully.