简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM