Force Delete StatefulSet and Pods

Kubernetes version 1.13.2

Issue description

I encountered the problem that when delete statefulset the execution hangs, for example:

1
kubectl delete statefulset is-en-conductor

it cannot delete the statefulset and associated pods at all

1
2
3
4
5
6
7
8
9
[root@opsft-lb-1 OpenShift] oc get all
NAME DESIRED CURRENT AGE
statefulsets/is-en-conductor 0 1 5h
statefulsets/is-engine-compute 0 2 5h

NAME READY STATUS RESTARTS AGE
po/is-en-conductor-0 0/1 Terminating 2 1h
po/is-engine-compute-0 1/1 Running 0 5h
po/is-engine-compute-1 0/1 Terminating 0 5h

Solution

1
kubectl delete statefulsets <statefulset name> --force --grace-period=0 --cascade=false

now we only have hanging pods, force delete them

1
2
3
4
NAME                     READY     STATUS        RESTARTS   AGE
po/is-en-conductor-0 0/1 Terminating 2 1h
po/is-engine-compute-0 1/1 Running 0 5h
po/is-engine-compute-1 0/1 Terminating 0 5h
1
kubectl delete pod <pod name> --force --grace-period=0
0%