<p>I need a bash script to delete only pods on specific node before shutdown or reboot using Kubernetes API.</p>

<p>Found a solution that works for what I'm trying to achieve:</p>

<pre><code>for each in $(curl -XGET https://URL/api/v1/namespaces  | jq -r '.items[].metadata.name'); 
  do arr=($(curl -XGET https://URL/api/v1/namespaces/$each/pods  | jq --arg node `hostname` -r '.items[] | select(.spec.nodeName == $node) | .metadata.name')); 
  for i in  ${arr[@]}; 
    do curl -XDELETE https://URL/api/v1/namespaces/$each/pods/$i ;
  done 
done
</code></pre>

<p>This is a script present on each Worker node and it's executed before each reboot or shutdown and deletes all the pods from all namespaces that are present on that node only. Before this, there is another command that marks the node as "unschedulable". If anyone is interested in this, I can post the complete solution</p>
