I'm trying to implement livenessProbes on pods running under K8s. Only very simple probe is working, see example:
livenessProbe:
exec:
command:
- cat
- /etc/services
initialDelaySeconds: 45
timeoutSeconds: 5
Probe I need to implement is killing pod every 50sec.
livenessProbe:
exec:
command:
mongo --port 27018 --eval "rs.status()" | grep "REMOVED" ; test $? -eq 1
initialDelaySeconds: 45
timeoutSeconds: 5
When probe is not implemented and command run inside a pod it is returning 1 if REMOVED string found and 0 if not found as required.
[root@eas-mongo-rs-3-ui81p /]# mongo --port 27018 --eval "rs.status()" | grep "REMOVED" ; test $? -eq 1
Question is, how to implement such command as Container Exec Check.
Regards
Your command will be quoted and not run as you think, if you want to use pipelines and other more advanced shell functionalities, you can use /bin/sh
, a workaround you can also see in the official documentation.
So your probe would look something like this:
livenessProbe:
exec:
command:
- /bin/sh
- -c
- mongo --port 27018 --eval "rs.status()" | grep -vq "REMOVED"
initialDelaySeconds: 45
timeoutSeconds: 5
You can also use the -v
switch to grep to avoid the reversing of the status with that extra test
command.