<p>I am writing a script that runs each minute and looks for newly created pods. The script executes commands within these pods.</p>
<p>I need to add the missing part to my current solution which looks like this:</p>
<pre><code>while true; do
  pods= $(kubectl get pods --field-selector status.phase=='Running' ---------- someting should be here ----------)
    for pod in ${pods[@]} ; do
    actions
    done
  sleep 60;
done

</code></pre>

<p>My current solution looks like this. Please feel free to review and enhance.</p>
<pre><code>current_pods=$(kubectl get pods | grep &quot;Running&quot; | awk '{print $1}')
# attach existing pods    
for pod in $current_pods; do
  do-something
done
# attach newly created pods each 60s
while true; do
  new_pods=$(kubectl get pods | grep &quot;Running&quot; | awk '{print $1}')
    for pod in $new_pods; do
      if [[ ! &quot; ${current_pods[@]} &quot; =~ $pod ]]; then
        do-something
      fi
    done
  current_pods=$new_pods
  sleep 60;
done
</code></pre>
