I am trying to execute this command through a Kubernetes livenessProbe, and I don't think it's working as expected as I see that the probe has failed in the pod events log. This is the command:
sh -c reply=$(curl -s -o /dev/null -w %{http_code} http://127.0.0.1:8080/login); if [ "$reply" -lt 200 -o "$reply" -ge 400 ]; then exit 1; fi;
When I exec into the container and run this command, I get this error:
/bin/sh: 1: [: Illegal number:
I echo $reply and nothing is stored in the reply variable after running the above command. When I run the command without the 'sh -c' part, it works and the variable reply is getting populated. Somehow, the sh command is not able to read the output of the curl command...I tried to remove the -o /dev/null part of the curl request and that does not help.
How can I get this command to execute?
To run
sh -cwith multiple synchronous commands, you need to enclose them inside quotes (either"or') and add backslash before any similar quotes using inside the command and before the dollar sign$of the variable