Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drain a node using kubernetes python client?

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?

like image 654
Swarup Donepudi Avatar asked Aug 28 '26 20:08

Swarup Donepudi


1 Answers

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 :)

like image 84
Swarup Donepudi Avatar answered Sep 01 '26 00:09

Swarup Donepudi