我已经用命令启动了豆荚

$ kubectl run busybox \
--image=busybox \
--restart=Never \
--tty \
-i \
--generator=run-pod/v1

出了点问题,现在我没法删除这个Pod了。

我尝试使用下面描述的方法,但Pod不断被重新创建。

$ 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

当前回答

我也遇到过这个问题,我已经用下面的命令删除部署了。

kubectl delete deployments DEPLOYMENT_NAME

但是仍然在重新创建豆荚,所以我使用下面的命令交叉检查副本集

kubectl get rs

然后将复制集编辑为1到0

kubectl edit rs REPICASET_NAME

其他回答

我也遇到过这个问题,我已经用下面的命令删除部署了。

kubectl delete deployments DEPLOYMENT_NAME

但是仍然在重新创建豆荚,所以我使用下面的命令交叉检查副本集

kubectl get rs

然后将复制集编辑为1到0

kubectl edit rs REPICASET_NAME

如果你的pod有一个像name-xxx-yyy这样的名字,它可以被一个replicasets控制。名为name-xxx的应用程序,在删除pod之前,你应该先删除该副本集:

kubectl delete replicasets.apps name-xxx

这里的许多答案都告诉我们删除一个特定的k8s对象,但你可以一次删除多个对象,而不是一个一个地删除:

Kubectl删除部署、作业、服务、pods——所有-n <命名空间>

在我的例子中,我使用OLM -操作员生命周期管理器运行OpenShift集群。OLM是控制部署的人,所以当我删除部署时,它不足以阻止pods重新启动。

只有当我删除OLM及其订阅时,部署、服务和pod才消失了。

首先列出命名空间中的所有k8s对象:

$ kubectl get all -n openshift-submariner

NAME                                       READY   STATUS    RESTARTS   AGE
pod/submariner-operator-847f545595-jwv27   1/1     Running   0          8d  
NAME                                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/submariner-operator-metrics   ClusterIP   101.34.190.249   <none>        8383/TCP   8d
NAME                                  READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/submariner-operator   1/1     1            1           8d
NAME                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/submariner-operator-847f545595   1         1         1       8d

OLM没有与get all一起列出,所以我专门搜索了它:

$ kubectl get olm -n openshift-submariner

NAME                                                      AGE
operatorgroup.operators.coreos.com/openshift-submariner   8d
NAME                                                             DISPLAY      VERSION
clusterserviceversion.operators.coreos.com/submariner-operator   Submariner   0.0.1 

现在删除所有对象,包括olm、订阅、部署、副本集等:

$ kubectl delete olm,svc,rs,rc,subs,deploy,jobs,pods --all -n openshift-submariner

operatorgroup.operators.coreos.com "openshift-submariner" deleted
clusterserviceversion.operators.coreos.com "submariner-operator" deleted
deployment.extensions "submariner-operator" deleted
subscription.operators.coreos.com "submariner" deleted
service "submariner-operator-metrics" deleted
replicaset.extensions "submariner-operator-847f545595" deleted
pod "submariner-operator-847f545595-jwv27" deleted

再次列出对象-全部消失:

$ kubectl get all -n openshift-submariner
No resources found.

$ kubectl get olm -n openshift-submariner
No resources found.

而不是试图弄清楚它是否是一个部署,deamonset, statefulset…或者什么(在我的情况下,它是一个复制控制器,不断跨越新的pod:) 为了确定是什么在图像上不断扩展,我用这个命令得到了所有的资源:

kubectl get all

当然,你也可以从所有命名空间中获取所有资源:

kubectl get all --all-namespaces

或者定义你想要检查的命名空间:

kubectl get all -n NAMESPACE_NAME

一旦我看到复制控制器是我的麻烦,我删除了它:

kubectl delete replicationcontroller/CONTROLLER_NAME

您可以根据年龄或时间执行kubectl get replicasets检查旧部署

如果要删除相同的应用程序当前运行pod,请根据时间删除旧部署

kubectl delete replicasets <Name of replicaset>