I have 2 pods running. They are;
- mail-services-pod
- redis-pod
I need to make sure that the redis server is (via redis-pod) up and running before creating the mail-services-pod as its is dependant on redis-pod.
I am new to kubernetes and would like to know what are the best ways to implement this check.
Cheers
2
Answers
Kubernetes is a distributed environment and instances will change e.g. address on deployment on new versions of your apps.
It is important that your app is recilient e.g. to network issues, and that your app properly do retry if a connection fails.
When recilient connections is properly handled by your app, the start order of your apps is no longer an issue.
So the best way I believe this can be done is via an initContainer
So let me use a contrived example. I want to start any app named
some-app-that-uses-redis
which usesalpine
in my example before redis starts.I would use a pod with an
initContainer
to do a little check to see if redis is up and running:The meat of the check is the following bit, which is just a for loop that does a redis query to the service where redis should work.
Then I’d make sure redis is part of a service so that this test will always be true:
If I understand things correctly, pods should only speak to other pods by means of services anyway.