I am running MongoDB as a StatefulSet in Kubernetes.
I am trying to use startup/liveness probes, I noticed some helm charts use the MongoDB "ping" command.
As the documentationsays,
The ping command is a no-op used to test whether a server is responding to commands. This command will return immediately even if the server is write-locked:
What does it mean? When a server is starting or in the midst of initial sync, what will the command return? Many thanks!
Not sure if the ping is a good idea, you don't care about the general state of the server, you care that it can receive connections.
liveness probes have a timeout, so it's possible that in the future when you're starting a new replica the new pod in the stateful set will fail while waiting for the replication to end.
You should use the rs.status() and get the "myState" field.
myState is an integer flag between 0-10. See this for all the possible statuses.
And if, for whatever reason rs.status() command fails, that means that the ping would also fail.
However, a successful ping doesn't mean that the server is ready to receive connections and serve data, which is what you really care about.
startup probe, myState equals to 1 or 2
this means that the startup probe will wait patiently until the server is ready, regardless if it's a primary or replica.
readiness probes, myState equals to 1 or 2
this means that, whenever a replica needs to rollback or is recovering or whatever reason that mongod decides that it's not ready to accept connections or serve data, this will let kubernetes know that this pod is not ready, and will route requests to other pods in the sts.
livenes probe, myState is NOT equals to 6, 8 or 10
That means that, unless the server status is UNKOWN, DOWN or REMOVED, kubernetes will assume that this server is alive.
So, let's test a scenario!
all good :)