How do I force delete kubernetes pods?

前端 未结 7 1958
渐次进展
渐次进展 2021-01-31 07:58

I have the following pods:

NAME                                                 READY     STATUS        RESTARTS   AGE
xxx-myactivities-79f49cdfb4-nwg22                  


        
相关标签:
7条回答
  • 2021-01-31 08:02

    To clean the pods you need to delete their deployments namespace.

    First discover that deployments existed:

    $ kubectl get deployments --all-namespaces
    NAME                               READY     STATUS        RESTARTS   AGE
    chetabahana-web-584b95d576-62ccj   1/1       Running       0          20m
    tutorial-web-56fbccc56b-wbwjq      1/1       Running       0          1m
    

    Delete the deployment <NAME>-xxxx like this:

    $ kubectl delete deployment <NAME>
    

    For example to delete tutorial-web-56fbccc56b-wbwjq run:

    $ kubectl delete deployment tutorial
    

    Then all corresponded pods of tutorial-xxxx will terminate by itself.

    NAME                               READY     STATUS        RESTARTS   AGE
    chetabahana-web-584b95d576-62ccj   1/1       Running       0          20m
    tutorial-web-56fbccc56b-wbwjq      0/1       Terminating   0          1m
    
    0 讨论(0)
  • 2021-01-31 08:02

    I'm using this:

    kubectl get pods | grep part-of-the-pods-name|awk '{split($0,a," "); print a[1]}'|xargs -I {} kubectl delete pods {} --grace-period=0
    

    additional grep can be added if needed.

    0 讨论(0)
  • 2021-01-31 08:03

    You have these alternatives:

    kubectl delete pod xxx --now 
    

    Or

    SSH into the node the stuck pod was scheduled on Running docker ps | grep {pod name} to get the Docker Container ID Running docker rm -f {container id}

    Or

    kubectl delete pod NAME --grace-period=0 --force
    
    0 讨论(0)
  • 2021-01-31 08:09

    For deleting pod forcefully use this.

    kubectl delete pod <Pod_Name> -n <namespace_name> --grace-period=0 --force

    OR

    kubectl delete pod <Pod_Name> -n <namespace_name> --wait=false

    For reference please follow below link. https://kubernetes.io/docs/tasks/run-application/force-delete-stateful-set-pod/

    0 讨论(0)
  • 2021-01-31 08:15

    To delete all pods in terminating state with one command do:

    for p in $(kubectl get pods | grep Terminating | awk '{print $1}'); do kubectl delete pod $p --grace-period=0 --force;done
    
    0 讨论(0)
  • 2021-01-31 08:21
    kubectl get pod --all-namespaces | awk '{if ($4 != "Running") system ("kubectl -n " $1 " delete pods " $2  " --grace-period=0 " " --force ")}'
    

    you can use this command

    0 讨论(0)
提交回复
热议问题