Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to define if one of kubernetes pods is not ready, using jsonpath and shell scripts?

I have a script with command that is sleeping if pods with specific labels is not ready. But it does not work if there are a few pods (in this way it need to be like condition != "true true true"). How can I check, if one of any pods is not ready (ready = false)?

while [ "$(kubectl get pods -l=app.kubernetes.io/instance=loki -n grafana -o jsonpath='{.items[*].status.containerStatuses[0].ready}')" != "true" ]; do
   sleep 5
   echo "Waiting for Loki to be ready."
done

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could just check to see if any pods have .ready equal to false like this:

while kubectl get pods \
    -l=app.kubernetes.io/instance=loki \
    -n grafana \
    -o jsonpath='{.items[*].status.containerStatuses[0].ready}' | grep -q false; do
   echo "Waiting for Loki to be ready."
   sleep 5
done
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading