【发布时间】:2018-11-27 20:21:39
【问题描述】:
团队, 我需要删除有错误的 k8s 集群上的 10 个 pod。 我得到它们如下:
kubectl get pods --all-namespaces | grep -i -e Evict -e Error | awk -F ' ' '{print $1, $2, $4}'
test-asdfasdf asdfasdf2215251 Error
test-asdfasdf asdfasdf2215252 Error
test-asdfasdf asdfasdf2215253 Error
test-asdfasdf asdfasdf2215254 Error
test-asdfasdf asdfasdf2215255 Error
test-asdfasdf asdfasdf2215256 Error
像这样手动删除它们:
kubectl delete pod asdfasdf2215251 -n test-asdfasdf
但是我可以编写一个脚本来查找任何 pod 上的错误并删除所有这些吗?我自己正在编写脚本,但对此很陌生,因此迟到了..
【问题讨论】:
-
ubectl 获取 pod --all-namespaces | grep -i -e 驱逐 -e 错误 | awk -F ' ' '{打印 $1, $2, $4}' | kubectl delete pod $2 -n $1 这没有帮助。
-
` awk -F ' ' '{print $1, $2, $4}'` 在
-F ''和'{print $1, $2, $4}'之间没有空格 -
kubectl 获取 pod --all-namespaces | grep -i -e 驱逐 -e 错误 | awk -F ' ' '{打印 $1, $2, $4}' | kubectl delete pod $2 -n $1 this does not identify -n which is used as namespace flag.
标签: bash kubernetes kubectl