我已经用命令启动了豆荚

$ 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

当前回答

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

kubectl delete replicasets.apps name-xxx

其他回答

我遇到了类似的问题:删除部署(kubectl delete deploy <name>)后,pod保持“Running”,删除后自动重新创建(kubectl delete po <name>)。

事实证明,由于某些原因,相关的副本集没有被自动删除,删除后(kubectl delete rs <name>),可以删除pods。

这将提供关于所有pod、部署、服务和作业的信息 在命名空间中。

kubectl get pods,services,deployments,jobs

pod既可以由部署创建,也可以由作业创建

kubectl delete job [job_name]
kubectl delete deployment [deployment_name]

如果您删除了部署或作业,那么可以停止重新启动pods。

在我的例子中,我通过像kubectl apply -f deployment这样的YAML文件进行部署。解决方案似乎是通过kubectl delete -f deployment.yaml删除

在学习了一个交互式教程后,我最终得到了一堆pod、服务和部署:

me@pooh ~ > kubectl get pods,services
NAME                                       READY   STATUS    RESTARTS   AGE
pod/kubernetes-bootcamp-5c69669756-lzft5   1/1     Running   0          43s
pod/kubernetes-bootcamp-5c69669756-n947m   1/1     Running   0          43s
pod/kubernetes-bootcamp-5c69669756-s2jhl   1/1     Running   0          43s
pod/kubernetes-bootcamp-5c69669756-v8vd4   1/1     Running   0          43s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   37s
me@pooh ~ > kubectl get deployments --all-namespaces
NAMESPACE     NAME                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
default       kubernetes-bootcamp   4         4         4            4           1h
docker        compose               1         1         1            1           1d
docker        compose-api           1         1         1            1           1d
kube-system   kube-dns              1         1         1            1           1d

要清理所有内容,删除—一切正常:

me@pooh ~ > kubectl delete pods,services,deployments --all
pod "kubernetes-bootcamp-5c69669756-lzft5" deleted
pod "kubernetes-bootcamp-5c69669756-n947m" deleted
pod "kubernetes-bootcamp-5c69669756-s2jhl" deleted
pod "kubernetes-bootcamp-5c69669756-v8vd4" deleted
service "kubernetes" deleted
deployment.extensions "kubernetes-bootcamp" deleted

这给我留下了一个空的Kubernetes集群:

me@pooh ~ > kubectl get pods,services,deployments
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   8m

在我的例子中,我使用下面这些

kubectl get all --all-namespaces 
kubectl delete deployment statefulset-deploymentnament(choose your deployment name)
kubectl delete sts -n default(choose your namespace) --all 
kubectl get pods --all-namespaces

问题得到了解决