code

Kubernetes 포드가 삭제되면 다시 생성됩니다.

codestyles 2020. 8. 20. 18:47
반응형

Kubernetes 포드가 삭제되면 다시 생성됩니다.


명령으로 포드를 시작했습니다.

$ 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

배포를 삭제해야합니다. 그러면 포드와 복제본 세트가 삭제됩니다. https://github.com/kubernetes/kubernetes/issues/24137

모든 배포를 나열하려면 :

kubectl get deployments --all-namespaces

그런 다음 배포를 삭제하려면 :

kubectl delete -n NAMESPACE deployment DEPLOYMENT

여기서 NAMESPACE는 그것이있는 네임 스페이스이고 DEPLOYMENT는 배포의 네임 스페이스 name입니다.

어떤 경우에는 작업이나 데몬 셋으로 인해 실행 중일 수도 있습니다. 다음을 확인하고 적절한 삭제 명령을 실행하십시오.

kubectl get jobs

kubectl get daemonsets.app --all-namespaces

kubectl get daemonsets.extensions --all-namespaces

포드에라는 이름이있는 경우 이름 name-xxx-yyy이라는 replicasets.apps에 의해 제어 될 수 있습니다 name-xxx. 포드를 삭제하기 전에 먼저 해당 복제 세트를 삭제해야합니다.

kubectl delete replicasets.apps name-xxx


배포, deamonset, statefulset ... 또는 무엇 (제 경우에는 새 포드를 계속 확장하는 복제 컨트롤러였습니다.)인지 파악하려고하는 대신 이미지를 계속 확장하는 것이 무엇인지 확인하기 위해 이 명령으로 모든 리소스를 얻었습니다.

kubectl get all

물론 모든 네임 스페이스에서 모든 리소스를 가져올 수도 있습니다.

kubectl get all --all-namespaces

또는 검사 할 네임 스페이스를 정의하십시오.

kubectl get all -n NAMESPACE_NAME

복제 컨트롤러가 내 문제에 대한 책임이 있음을 확인한 후 삭제했습니다.

kubectl delete replicationcontroller/CONTROLLER_NAME


상태 저장 세트도 찾아보십시오.

kubectl get sts --all-namespaces

네임 스페이스의 모든 상태 저장 세트를 삭제하려면

kubectl --namespace <yournamespace> delete sts --all

하나씩 삭제하려면

kubectl --namespace ag1 delete sts mssql1 
kubectl --namespace ag1 delete sts mssql2
kubectl --namespace ag1 delete sts mssql3

In some cases the pods will still not go away even when deleting the deployment. In that case to force delete them you can run the below command.

kubectl delete pods podname --grace-period=0 --force


When the pod is recreating automatically even after the deletion of the pod manually, then those pods have been created using the Deployment. When you create a deployment, it automatically creates ReplicaSet and Pods. Depending upon how many replicas of your pod you mentioned in the deployment script, it will create those number of pods initially. When you try to delete any pod manually, it will automatically create those pod again.

Yes, sometimes you need to delete the pods with force. But in this case force command doesn’t work.


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.


Instead of removing NS you can try removing replicaSet

kubectl get rs --all-namespaces

Then delete the replicaSet

kubectl delete rs your_app_name

After taking an interactive tutorial I ended up with a bunch of pods, services, deployments:

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

To clean up everything, delete --all worked fine:

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

That left me with (what I think is) an empty Kubernetes cluster:

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

If you have a job that continues running, you need to search the job and delete it:

kubectl get job --all-namespaces | grep <name>

and

kubectl delete job <job-name>


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>

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

The root cause for the question asked was the deployment/job/replicasets spec attribute strategy->type which defines what should happen when the pod will be destroyed (either implicitly or explicitly). In my case, it was Recreate.

As per @nomad's answer, deleting the deployment/job/replicasets is the simple fix to avoid experimenting with deadly combos before messing up the cluster as a novice user.

Try the following commands to understand the behind the scene actions before jumping into debugging :

kubectl get all -A -o name
kubectl get events -A | grep <pod-name>

참고URL : https://stackoverflow.com/questions/40686151/kubernetes-pod-gets-recreated-when-deleted

반응형