快速清除k8s长期处于删除状态的pod

March 27, 2020 默认分类

快速清除k8s长期处于删除状态的pod

k8s master 操作
#/bin/bash
LINE=$(kubectl get pod --all-namespaces|grep "Terminating"|awk '{print $1"/"$2}')
for i in ${LINE[@]}
  do
  NAMESPACES=$(echo $i|awk -F/ '{print $1}')
  POD_NAME=$(echo $i|awk -F/ '{print $2}')
  kubectl delete pod --force --grace-period=0 -n $NAMESPACES $POD_NAME
done
节点操作
#/bin/bash
for ((i=1;i<=3;i++));
  do
    ERROR_CONTAINER=$(systemctl status kubelet -l|grep "can't make reference"|awk '{print $16}'|sed -e 's/"//g'|awk -F'(' '{print $1}'|xargs |sed -e "s/ /|/g")
    docker rm -f $(docker ps -a|grep -E "$ERROR_CONTAINER"|awk '{print $1}')
done
systemctl restart kubelet

已有 5 条评论

  1. Good way of telling, and pleasant article to take information on the topic of my presentation focus, which i am going
    to convey in academy. agen judi online indonesia

  2. Great article. http://imfl.sci.pfu.edu.ru

  3. Pretty section of content. I just stumbled upon your site and in accession capital to assert that I get actually enjoyed account your blog posts.
    Anyway I will be subscribing to your feeds and even I achievement you access consistently quickly.
    https://bayareahot.com/

  4. Thanks for ones marvelous posting! I certainly enjoyed
    reading it, you happen to be a great author.I will be sure to bookmark your blog and will come back from now on. I want to encourage yourself to
    continue your great posts, have a nice weekend! http://www.ccwin.cn

  5. Good answers in return of this query with solid arguments and explaining all about that.

添加新评论