<p>I am trying to automate kubernetes worker nodes using the official <a href="https://github.com/kubernetes-incubator/client-python" rel="noreferrer">kubernetes python-client</a>. I am currently looking for a way to <a href="https://kubernetes.io/docs/tasks/administer-cluster/safely-drain-node/" rel="noreferrer">safely move al the running applications to other nodes</a> . We can do so using "kubectl drain". I did not find a way to simulate that functionality using python client. I am currently looking into Does this library support drain functionality yet?</p>

<p>I found the answer. Python client does have support for draining a node but it is not a single command. "kubectl drain" operation utilizes <a href="https://kubernetes.io/docs/tasks/administer-cluster/safely-drain-node/#the-eviction-api" rel="noreferrer">Eviction API</a> to safely delete all the workloads running on a node. The python-client has a function <a href="https://github.com/kubernetes-incubator/client-python/blob/master/kubernetes/docs/CoreV1Api.md#create_namespaced_pod_eviction" rel="noreferrer">create_namespaced_pod_eviction</a> that safely deletes all the pods in a namespace. However, "safely" depends on the <a href="https://kubernetes.io/docs/tasks/run-application/configure-pdb/" rel="noreferrer">Pod Disruption Budgets (PDB)</a> that you have defined for the apps running on that node.</p>

<p>I am posting this answer hoping that someone might find it useful :)</p>
