-1

Is there a way to delete a k8s deployment using python? the official k8s python client lacks this feature, you can only delete pods & services I tried doing it using [subprocess] but I'd like to explore other options

def delete_deployment(deployment_name, name_space):
    subprocess.run(f'kubectl delete deployment {deployment_name} -n {name_space}',shell=True)
  • 1
    You can't call [`delete_namespaced_deployment`](https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md#delete_namespaced_deployment)? – David Maze Dec 01 '22 at 12:23
  • I was using client.CoreV1Api() and it didn't have this function, but when i follow what u said and called it via client.AppsV1Api() it worked! thanks – Atheer Abdullatif Dec 01 '22 at 13:01

1 Answers1

0

You can delete a deployment by the following:

   k8s_apps_v1 = client.AppsV1Api()
   k8s_apps_v1.delete_namespaced_deployment('dep_name','name_space')