Kubernetes - 平均node资源

2022-12-21
#!/bin/bash
namespace="pro"
clusters="pro pro-internet"
echo `date`
for cluster in ${clusters}
do
    high_nodes=$(/usr/local/bin/kubectl --kubeconfig /root/.kube/all-config/${cluster} top node | awk '{print $1,$NF}' | grep -v NAME | sed 's/%//g' | awk '$2>93''{print $1}')
    for high_node in ${high_nodes}
    do
        temp_file="/tmp/pod-resource-${high_node}"
        rm -f ${temp_file}
        /usr/local/bin/kubectl --kubeconfig /root/.kube/all-config/${cluster} -n ${namespace} get pod -o wide | grep ${high_node} | awk '{print $1}' | while read pod
        do
            /usr/local/bin/kubectl --kubeconfig /root/.kube/all-config/${cluster} -n ${namespace} top pod ${pod} | grep -v NAME | awk '{print $3,$1}' >> ${temp_file}
        done
        delete_pod=$(cat ${temp_file} | egrep -v "39016|40001|50010|40002|37002|42001" | sort -nk1 | tail -n1 | awk '{print $2}')
        if [[ ! -z ${delete_pod} ]];then
            /usr/local/bin/kubectl --kubeconfig /root/.kube/all-config/${cluster} -n ${namespace} delete pod ${delete_pod}
       fi
       sleep 300
    done
done

标题:Kubernetes - 平均node资源
地址:https://blog.njqhome.com:8443/articles/2022/10/24/1666581055615.html