I am creating pods in kubernetes environment on linux machine. I would like to wait till all pods are in Running state. I have written while loop in bash but it is still looping even the podstatus (variable) does not have "false" value in it. Thanks for any help!
verifyPods(){
timer=0
msg="false"
while [[ $timer -lt 15 && "false" == *"$msg"* ]] ;do
sleep 10
((timer=timer+1))
echo "Timer current value >> $timer and Pods statuses >> $podstatus"
podstatus=$(kubectl -n $ns get pods -o custom columns=metadata.name:status.containerStatuses[*].ready | grep true)
echo "Pod status is >> $podstatus and Timer is >> $timer"
done
}
Printed Output:
Pod status is >> true
true
true
true,true
true
true,true
true
true and Timer is >> 14
Timer current value >> 15 and Pod statuses >> true
true
An alternative approach is to use kubectl wait
You could:
kubectl wait pod \
--all \
--for=condition=Ready \
--namespace=${ns}