<p>I need to find the number of pods currently NOT terminated (can be available, terminating, etc.) in order to prevent deployment from starting if there are still some pods not terminated.</p>
<p>UPDATE: If there are no pods available, I should get &quot;0&quot;. Is it possible ?</p>

tumm
<p>You can try:</p>
<p><code>kubectl get pods --field-selector=status.phase!=Succeeded,status.Phase!=Failed</code></p>
<p>If you look at the <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase" rel="noreferrer">Pod Phases</a> you can see that this covers all possible pods where all containers are terminated (either failed or succeeded)</p>
<p>If you specifically want the count you could use a bit of <code>jq</code> and use:</p>
<pre><code>kubectl get pods --field-selector=status.phase!=Succeeded,status.Phase!=Failed --output json | jq -j '.items | length'
</code></pre>
<p>This returns the # of pods that are not <code>Terminated</code>.</p>
