shell - 重启占用内存top 20的pod
2022-03-08
namespace维度重启占用内存top 20的pod优雅重启
#!/bin/bash
stime=$(date "+%s")
namespaces="qa qa2 qa3"
for namespace in ${namespaces}
do
deployments=$(/usr/bin/kubectl -n ${namespace} top pod --sort-by=memory | head -n30 | grep "ws-" |awk '{print $1}' | awk -F '-' '{print $1"-"$2"-"$3"-"$4}')
for deployment in ${deployments}
do
/usr/bin/kubectl -n ${namespace} patch deployment ${deployment} -p '{"spec":{"template":{"metadata":{"annotations": {"sTime":'\"${stime}\"'} } }}}'
sleep 5
done
done