如何强制删除kubernetes pods?

时间:2018-05-14 18:20:09

标签: kubernetes

我有以下豆荚:

NAME                                                 READY     STATUS        RESTARTS   AGE
xxx-myactivities-79f49cdfb4-nwg22                      1/1       Terminating   0          10h
xxx-mysearch-55864b5c59-6bnwl                          1/1       Terminating   0          1d
xxx-mysearch-55864b5c59-rpn48                          1/1       Terminating   0          13h
xxx-mysearch-6ff9bbb7cb-9qgbb                          1/1       Terminating   0          3d

我正在运行以下代码来强行删除这些pod:

#
# Clean up dying pods
#
pods=$( kubectl get pods | grep -v Running | tail -n +2 | awk -F " " '{print $1}' )
for pod in $pods;
do
    kubectl delete pod $pod --force
done

这是输出:

pod "xxx-myactivities-79f49cdfb4-nwg22" deleted
pod "xxx-mysearch-55864b5c59-6bnwl" deleted
pod "xxx-mysearch-55864b5c59-rpn48" deleted
pod "xxx-mysearch-6ff9bbb7cb-9qgbb" deleted

清理完毕后,这些豆荚仍然徘徊。

NAME                                                 READY     STATUS        RESTARTS   AGE
xxx-myactivities-79f49cdfb4-nwg22                      1/1       Terminating   0          10h
xxx-mysearch-55864b5c59-6bnwl                          1/1       Terminating   0          1d
xxx-mysearch-55864b5c59-rpn48                          1/1       Terminating   0          13h
xxx-mysearch-6ff9bbb7cb-9qgbb                          1/1       Terminating   0          3d

如何清理这些豆荚?

7 个答案:

答案 0 :(得分:13)

你有这些选择:

kubectl delete pod xxx --now 

或者

SSH进入节点,计划卡住的pod 运行docker ps | grep {pod name}以获取Docker容器ID 正在运行docker rm -f {container id}

或者

kubectl delete pod NAME --grace-period=0 --force

答案 1 :(得分:7)

  

您需要首先发现存在部署:

<NAME>-xxxx

像这样删除部署kubectl delete deployment <NAME>

tutorial-web-56fbccc56b-wbwjq

例如要删除kubectl delete deployment tutorial ,请执行以下操作:

tutorial-xxxx

然后NAME READY STATUS RESTARTS AGE chetabahana-web-584b95d576-62ccj 1/1 Running 0 20m tutorial-web-56fbccc56b-wbwjq 0/1 Terminating 0 1m 的所有对应豆荚将自行终止。

for

答案 2 :(得分:7)

要强制删除吊舱,请使用此功能。

kubectl delete pod <Pod_Name> -n <namespace_name> --grace-period=0 --force

OR

kubectl delete pod <Pod_Name> -n <namespace_name> --wait=false

作为参考,请点击以下链接。 https://kubernetes.io/docs/tasks/run-application/force-delete-stateful-set-pod/

答案 3 :(得分:1)

要使用一个命令删除处于终止状态的所有Pod,请执行以下操作:

for p in $(kubectl get pods | grep Terminating | awk '{print $1}'); do kubectl delete pod $p --grace-period=0 --force;done

答案 4 :(得分:1)

万一您使用Helm安装Pod了,

helm delete Your_Deployment_Name -n The_Namespace

答案 5 :(得分:1)

我正在使用它:

The getEnumeration method returns a java.util.Enumeration that is used to scan the queue's messages.

如果需要,可以添加其他grep。

答案 6 :(得分:0)

kubectl get pod --all-namespaces | awk '{if ($4 != "Running") system ("kubectl -n " $1 " delete pods " $2  " --grace-period=0 " " --force ")}'

您可以使用此命令