6

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?

Eldad Assis
  • 10,464
  • 11
  • 52
  • 78
Swarup Donepudi
  • 984
  • 1
  • 11
  • 23

1 Answers1

16

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
  • 984
  • 1
  • 11
  • 23
  • Note that there's currently (July 2019) a method to [delete a node](https://github.com/kubernetes-client/python/blob/release-9.0/kubernetes/docs/CoreV1Api.md#delete_node) in the python-client. – Jaime M. Jul 01 '19 at 13:11