k8s对比不同环境获取副本数并更新

#!/bin/bash
scripts_path="/data/wudongyu/scripts"
read -p "请输入要参考的源环境名,获取k8s资源,譬如cassmall-hwprod、cassmall-hwbeta: " env_src
case ${env_src} in
cassmall-hwprod|cassmall-hwbeta|cassmall-hwci)
echo "输入的环境名正确,现在进行获取该环境的k8s资源信息"
su - ${env_src} -c kubectl get deployment -A -o wide |awk {‘print $1,$2,$4‘} > prod.txt
echo "获取k8s资源信息已完成";;
*)
echo "您输入的环境名错误,请重新运行脚本或联系管理员【吴东瑜】"
sleep 3
exit;;
esac
read -p "请输入要修改的目标环境的名称,譬如cassmall-hwprod、cassmall-hwbeta:" env_dest
case ${env_dest} in
cassmall-hwprod|cassmall-hwbeta|cassmall-hwci)
if [ ${env_src} == ${env_dest} ];then
echo "您输入的源环境和目标环境相同,执行脚本无意义,请退出重试"
exit
else
echo "您输入的环境名正确"
fi;;
*)
echo "您输入的环境名错误,请重新运行脚本或联系管理员【吴东瑜】"
exit;;
esac
read -p "请输入目标环境的副本数比例,比例数仅支持【0.25、0.5、0.75】: " rs_number
case ${rs_number} in
0.25|0.5|0.75)
cd ${scripts_path}
cat prod.txt |while read line;do
ns=`echo $line|awk ‘{print $1}‘`
dm=`echo $line|awk ‘{print $2}‘`
rs1=`echo $line|awk ‘{print $3}‘`
rs2=`echo "${rs1} * ${rs_number}"|bc`
new_rs=`awk -v a=${rs2} ‘BEGIN{print(int(a)==(a))?int(a):int(a)+1}‘`
#su - ${env_dest} -c kubectl scale --replicas=${new_rs} deploy/${dm} -n ${ns}
echo "已更新完成!!!"
done
*)
echo "您输入的副本数比例不符合要求,请重新运行脚本或联系管理员【吴东瑜】"
exit;;
esac

k8s对比不同环境获取副本数并更新

上一篇:三层交换机之L3


下一篇:while 循环和do...while 循环