Kubernetes-client: how to delete pod forcely?

Created on 6 Sep 2018  路  9Comments  路  Source: fabric8io/kubernetes-client

The function as "kubectl delete pod podName --grace-period=0 --force" ?

Most helpful comment

@rohanKanojia it seems that force is just a flag to make sure user knows what he is doing and provide backwards compatibility:
https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/delete/delete.go#L160
So graceperiod=0 should do the job as --force enforces grace period to 0 otherwise if that flag is not there period will be 1 as with the --now flag.

All 9 comments

Hey @lxl910915

Can you please try this if it resolves your problem.

client.pods().inNamespace(namespace).withName(podName).withGracePeriod(0).delete();

not right now, --force ,how to make

Hey @lxl910915

Can you please try this if it resolves your problem.

client.pods().inNamespace(namespace).withName(podName).withGracePeriod(0).delete();

can't resolve this problem, the command --force , how to use the client-api implement?

@liuchaoheliang : Hi, Have you checked if there is such implementation of force deletion in kubernetes rest api? I think it can be implemented

@rohanKanojia it seems that force is just a flag to make sure user knows what he is doing and provide backwards compatibility:
https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/delete/delete.go#L160
So graceperiod=0 should do the job as --force enforces grace period to 0 otherwise if that flag is not there period will be 1 as with the --now flag.

Hey @lxl910915
Can you please try this if it resolves your problem.
client.pods().inNamespace(namespace).withName(podName).withGracePeriod(0).delete();

Can we delete one more pods?

@yuwzho : Could you please elaborate what you're saying?

@rohanKanojia I have some pods to force delete (no specific label set, just names), can I make it in one(as less as possible) api call to save network overhead.

umm, just names. I don't think so. But if you have full objects then you can do something like:

client.resourceList(new PodListBuilder().withItems(pod1, pod2, pod3).build()).withGracePeriod(0).delete()

Thank you very much! It solves my problem!

Was this page helpful?
0 / 5 - 0 ratings