I want to evict all pods from a Kubernetes node by using the client-go package. Similar to kubectl drain <Node>. Possibly ignoring the kube-system namespace pods.
I've obtained the list of pods from a node by:
func evictNodePods(nodeInstance string, client *kubernetes.Clientset) {
pods, err := client.CoreV1().Pods("").List(metav1.ListOptions{
FieldSelector: "spec.nodeName=" + nodeInstance,
})
if err != nil {
log.Fatal(err)
}
for _, i := range pods.Items {
if i.Namespace == "kube-system" {
continue
} else {
//evict
}
}
}
But im not clear on how to send a POST request to evict the pods on a given node instance