0%

Kubernetes删除pod时会自动重新创建

问题描述

我已经用命令启动了pods:

1
# kubectl run busybox --image=busybox --restart=Never --tty -i --generator=run-pod/v1

出了点问题,现在我无法删除这个pod,我尝试使用下面的方法,但它不断重建自己:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# kubectl delete pods  busybox-na3tm
pod "busybox-na3tm" deleted
# kubectl get pods
NAME READY STATUS RESTARTS AGE
busybox-vlzh3 0/1 ContainerCreating 0 14s

# kubectl delete pod busybox-vlzh3 --grace-period=0

# kubectl delete pods --all
pod "busybox-131cq" deleted
pod "busybox-136x9" deleted
pod "busybox-13f8a" deleted
pod "busybox-13svg" deleted
pod "busybox-1465m" deleted
pod "busybox-14uz1" deleted
pod "busybox-15raj" deleted
pod "busybox-160to" deleted
pod "busybox-16191" deleted


# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default busybox-c9rnx 0/1 RunContainerError 0 23s

高票回答

您需要删除deployment,而deployment会自动删除pod和replica sets

列出所有deployment:

1
kubectl get deployments --all-namespaces

然后删除deployment:

1
kubectl delete -n NAMESPACE deployment DEPLOYMENT

NAMESPACE是其所在的命名空间,而DEPLOYMENT是deployment资源的名称。

在某些情况下,由于job或daemonset也可能正在运行。检查以下内容并运行相应的删除命令。

1
2
3
4
5
kubectl get jobs

kubectl get daemonsets.app --all-namespaces

kubectl get daemonsets.extensions --all-namespaces

原文链接

Kubernetes pod gets recreated when deleted