Bash + Kubectl - 等待所有 pod 都处于运行状态

use*_*964 1 bash kubectl

我正在 Linux 机器上的 kubernetes 环境中创建 pod。我想等到所有 Pod 都处于运行状态。我已经在 bash 中编写了 while 循环,但即使 podstatus (变量)中没有“false”值,它仍然在循环。谢谢你的帮助!


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
Run Code Online (Sandbox Code Playgroud)

Daz*_*kin 7

另一种方法是使用kubectl wait

你可以:

kubectl wait pod \
--all \
--for=condition=Ready \
--namespace=${ns}
Run Code Online (Sandbox Code Playgroud)