How to drain a node using kubernetes python client?

10/5/2017

I am trying to automate kubernetes worker nodes using the official kubernetes python-client. I am currently looking for a way to safely move al the running applications to other nodes . 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?

-- Swarup Donepudi
docker
kubernetes
kubernetes-go-client

1 Answer

10/5/2017

I found the answer. Python client does have support for draining a node but it is not a single command. "kubectl drain" operation utilizes Eviction API to safely delete all the workloads running on a node. The python-client has a function create_namespaced_pod_eviction that safely deletes all the pods in a namespace. However, "safely" depends on the Pod Disruption Budgets (PDB) that you have defined for the apps running on that node.

I am posting this answer hoping that someone might find it useful :)

-- Swarup Donepudi
Source: StackOverflow