kubernet批量删除某类pod脚本

环境:kubernet、centos7

思路:获取需要查询pod类——>获取关键字——>拼接并执行删除

1、脚本如下

cat /tmp/delete-pod.sh

#!/bin/bash
#获取需要的pod的name和namepsaces
kubectl get pods --all-namespaces|grep Error|awk '{print $2,$1}' > /tmp/tmp.txt
#逐行读取文件
cat /tmp/tmp.txt|while read -r line
   do 
#注意赋值不要有空格 name
=`echo $line|awk '{print $1}'` spaces=`echo $line|awk '{print $2}'` #删除pod #echo "kubectl delete pod $name -n $spaces" kubectl delete pod $name -n $spaces done

 

posted @ 2020-11-02 11:27  苍茫宇宙  阅读(338)  评论(0编辑  收藏  举报