Kubernetes pod gets recreated when deleted

2020-02-07 16:07发布

I have started pods with command

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

Something went wrong, and now I can't delete this Pod.

I tried using the methods described below but the Pod keeps being recreated.

$ 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

15条回答
手持菜刀,她持情操
2楼-- · 2020-02-07 16:41

if your pod has name like name-xxx-yyy, it could be controlled by a replicasets.apps named name-xxx, you should delete that replicaset first before deleting the pod

kubectl delete replicasets.apps name-xxx

查看更多
我想做一个坏孩纸
3楼-- · 2020-02-07 16:41

This will provide information about all the pods,deployments, services and jobs in the namespace.

kubectl get pods,services, deployments, jobs

pods can either be created by deployments or jobs

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

If you delete the deployment or job then restart of the pods can be stopped.

查看更多
小情绪 Triste *
4楼-- · 2020-02-07 16:41

You can do kubectl get replicasets check for old deployment based on age or time

Delete old deployment based on time if you want to delete same current running pod of application

kubectl delete replicasets <Name of replicaset>
查看更多
爱情/是我丢掉的垃圾
5楼-- · 2020-02-07 16:41

I also faced the issue, I have used below command to delete deployment.

kubectl delete deployments DEPLOYMENT_NAME

but still pods was recreating, So I crossed check the Replica Set by using below command

kubectl get rs

then edit the replicaset to 1 to 0

kubectl edit rs REPICASET_NAME
查看更多
Viruses.
6楼-- · 2020-02-07 16:41

In my case I deployed via a YAML file like kubectl apply -f deployment.yaml and the solution appears to be to delete via kubectl delete -f deployment.yaml

查看更多
Summer. ? 凉城
7楼-- · 2020-02-07 16:44

Instead of removing NS you can try removing replicaSet

kubectl get rs --all-namespaces

Then delete the replicaSet

kubectl delete rs your_app_name
查看更多
登录 后发表回答