<p>I am writing a script, where I want to restart kubernetes pods with the scale-down scale-up method</p>
<pre><code>kubectl scale --replicas=0 myPod -n myNamespace
kubectl scale --replicas=3 myPod -n myNamespace
</code></pre>
<p>I would like the script to wait until the pods are <code>Running</code> - so I thought something like</p>
<pre><code>while kubectl get pods --field-selector=status.phase=Running -n myNameSpace | grep -c myPod = 3;
    do
        sleep 1
        echo &quot;.&quot;
    done
</code></pre>
<p>could work - but no dice. The <code>= 3</code> part doesn't work.
I can't just use</p>
<pre><code>while kubectl get pods --field-selector=status.phase!=Running -n myNameSpace | grep -c myPod &gt; /dev/null
</code></pre>
<p>since the pods start in sequence, and I could get unlucky by querying just as one pod deployed, and others didn't even start.</p>
<p>How can I ensure that the script continues only after all 3 of the pods are <code>Running</code>?</p>

<p>Write your condition in [ ] and get the value of command with ` or $. for example in your case:</p>
<pre><code>while [ &quot;$(kubectl get pods --field-selector=status.phase=Running -n myNameSpace | grep -c myPod)&quot; != 3 ]

  do
    sleep 1
    echo &quot;wait&quot;
  done

echo &quot;All three pods is running and continue your script&quot;
</code></pre>
