<p>I want to evict all pods from a Kubernetes node by using the client-go package. Similar to <code>kubectl drain &lt;Node&gt;</code>. Possibly ignoring the <code>kube-system</code> namespace pods.</p>
<p>I've obtained the list of pods from a node by:</p>
<pre><code>func evictNodePods(nodeInstance string, client *kubernetes.Clientset) {

    pods, err := client.CoreV1().Pods(&quot;&quot;).List(metav1.ListOptions{
        FieldSelector: &quot;spec.nodeName=&quot; + nodeInstance,
    })

    if err != nil {
        log.Fatal(err)
    }
    for _, i := range pods.Items {
        if i.Namespace == &quot;kube-system&quot; {
            continue
        } else {
            //evict
        }
    }
}
</code></pre>
<p>But im not clear on how to send a POST request to evict the pods on a given node instance</p>

<p>To delete pod:</p>
<pre class="lang-golang prettyprint-override"><code>err := client.CoreV1().Pods(i.Namespace).Delete(i.Name, metav1.DeleteOptions{})
if err != nil {
  log.Fatal(err)
}
</code></pre>
<p>If you upgrade <code>client-go</code> to recent versions, you need to add <a href="https://golang.org/pkg/context/" rel="noreferrer">context</a> as a parameter too.</p>
<pre class="lang-golang prettyprint-override"><code>err := client.CoreV1().Pods(i.Namespace).Delete(context.TODO(), i.Name, metav1.DeleteOptions{})
if err != nil {
  log.Fatal(err)
}
</code></pre>
