How to negate exit code status to be used in Kubernetes livenessProbe?
I'll be using the grep command and I would like to do below as a check.
grep has no hitgrep has a hitSince normally, grep will return 0 if there is a hit, can I negate this something like shown below?
!$(cat filet.txt | grep keyword)Yes you can give it try
example :
livenessProbe:
exec:
command:
- /bin/bash
- -c
- cat filet.txt | grep keyword
initialDelaySeconds: 10
periodSeconds: 10you should checkout if helpful
-v, --invert-match
Invert the sense of matching, to select non-matching lines.You can also try -c
echo 'Test' | grep -c T1
echo 'Test' | grep -c N0
shell script
#!/bin/sh
if [ $(echo 'Test' | grep -c T) ]; then
exit 1
else
exit 0
fi
the easiest way would be writing shell script and managing the exit code for liveness as you want 0 or 1 and based on that liveness will restart the pod.
livenessProbe:
exec:
command:
- /bin/sh
- -c
- /home/test/health.sh