Kubernetes readinessProbe livenessProbe using script

Hi ,
I am trying to execute readiness/liveness probe using bash script as below but not able to redirect script output to container logs or standard out. Is it not possible to to route logs from script to container logs ? Any suggestion

livenessProbe:
  exec:
    command:
    - /bin/sh
    - /home/test/check.sh

The stdout/stderr of probes is not really captured. You could write it to a file?

It seems like a plausible feature request, but we’re swimming in those right now and I would not want to make anyone think it is the sort of thing that can just be slapped together.

I’ve tried with an std output to file and the files never gets updated:
echo "PROBE ok" >> /fails.txt

If you put that in the script it should run. If you put that in the tank it won’t. The yaml is an exec() not a full shell.

this is my script
#/bin/bash count=tail /console.txt | grep “mysstring” | wc -lif [[ count -eq 1 ]] then echo "PROBE FAILEDdate" >> /fails.txt exit 1 fi if [[ count -eq 0 ]] then echo "PROBE ok date" >> /fails.txt exit 0 fi
and my yaml
livenessProbe: initialDelaySeconds: 30 periodSeconds: 30 failureThreshold: 6 exec: command: ["/bin/sh","-c","/probe.sh"]
I don’t know about the tank… kind of new to Kubernetes scripts

The formatting is a bit messed up, but I assume you tested this script and it works?

Does the container user have access to write to / ?

Is it possible that the count is > 1 ?

Maybe log something at the top of this to convince yourself it is even running at all.

Hi @thockin / @Jose_Taboada Did the solution worked at all. I would like like believe that if write to a file as script output it should be collected via any tool to show up these probe logs. I have the similar requirement and I just want to make sure this worked and not getting into any unforseen one’s before I start over. Appreciate thought !

I have no further information. OP never responded.

ah , got it. I will try out the solution to redirect script stdout to file i.e. backed by EFS and collect logs off datadog agent. I will post the solution if works for me, thanks @thockin

1 Like