【问题标题】:How to delete all the pods which are in Error/Init/CrashloopBckoff state at one shot如何一次性删除所有处于 Error/Init/CrashloopBckoff 状态的 pod
【发布时间】:2020-09-30 02:28:28
【问题描述】:

我试过下面的命令。但是这个命令会获取所有由于某种原因没有运行的 pod 任何其他方式来做到这一点

kubectl delete pods -A --field-selector=status.phase!=Running

【问题讨论】:

    标签: docker kubernetes containers kubectl


    【解决方案1】:

    这可能是您正在寻找的,但使用 awk 和 unix 输出管道。

    kubectl get pods --field-selector 'status.phase=Failed' --all-namespaces | awk '{if ($4 != "Running") system ("kubectl -n " $1 " delete pods " $2 )}'
    

    【讨论】:

    • kubectl get pods --field-selector 'status.phase=Failed' --all-namespaces is not catch all the pods with STATUS != RUNNING .
    • @Gajukorse 删除 --field-selector 'status.phase=Failed'
    猜你喜欢
    • 2021-08-11
    • 1970-01-01
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 2018-02-28
    相关资源
    最近更新 更多