How to check if cassandra is up and running using initContainers

1/2/2021

In my kubernetes cluster, I have cassandra statefulset which is using cassandra:4.0 image. I want my application pods to wait for cassandra to be up & running first.

I suppose this can be done by adding an initContainers in application pod deployment. The initContainer will check the status of cassandra thereby blocking the application pod from starting till it assures the availability of cassandra.

I don't know how to create such initContainer for checking the status of cassandra statefulset, I've checked onthe web but didn't find any examples related to cassandra.

Any help would be highly appreciated.

Note: I'm not using the actual cassandra image and not this example one (gcr.io/google-samples/cassandra:v13)

-- Vivek
cassandra
kubernetes

1 Answer

1/4/2021

You could Wait for cassandra Service to be created, using a shell one-line command like:

for i in {1..100}; do sleep 1; if dig cassandraservice; then exit 0; fi; done; exit 1

Ref: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/

-- Abhijit Gaikwad
Source: StackOverflow