Day 2605 / Killing Kubernetes pods without breaking stuff Rancher
- To force-kill pods w/o breaking k8s:
kubectl delete pod <> --now
Ty KM (https://github.com/kkmarv) for the following, quoting verbatim:
The expected behaviour of kubectl delete heavily depends on its arguments. There are 4 possible but wrongly documented options. I’ve tried to compile different sources into this list:
kubectl delete pod <>will first send a SIGTERM, then a SIGKILL after X seconds (depends on the gracePeriods set by your pod)kubectl delete pod <> --grace-period=X(X>0) will first send a SIGTERM, then a SIGKILL after X secskubectl delete pod <> --nowis equivalent tokubectl delete pod <> --grace-period=1
There’s also --force
Where things are possible to go wrong. It immediately deletes the pod from etcd, which will NOT kill the pod. It will too wait for the grace period before sending a SIGKILL. But even then it is not guaranteed that resources will be freed. There is even a warning in kubectl delete --help about this. Only use this when there is no other way to kill a pod.
The force flag also allows to specify --grace-period=0 which will simply default to the grace period defined by the pod, effectively doing nothing since this is also the default behaviour.
(Preserving l/r width)