#!/bin/bash get_pods_file=/"data/wudongyu/scripts/get_pods.sh" #sed -i '1d' /data/wudongyu/scripts/prod.txt scripts_path="/data/wudongyu/scripts" read -p "请输入要参考的源环境名,获取k8s资源,譬如hwprod、hwbeta、hwprod-gray1: " env_src case ${env_src} inhwprod|hwbeta|hwci) echo "输入的环境名正确,现在进行获取该环境的k8s资源信息" su - ${env_src} -c "${get_pods_file}" echo "获取k8s资源信息已完成";; *) echo "您输入的环境名错误,请重新运行脚本或联系管理员【dongyu】" sleep 3 exit;; esac read -p "请输入要修改的目标环境的名称,譬如hwprod、hwbeta、hwprod-gray1、terminator:" env_dest case ${env_dest} inhwprod-gray1|hwbeta|hwci|terminator) if [ ${env_src} == ${env_dest} ];then echo "您输入的源环境和目标环境相同,执行脚本无意义,请退出重试" exit else echo "您输入的环境名正确" fi;; *) echo "您输入的环境名错误,请重新运行脚本或联系管理员【dongyu】" exit;; esac read -p "请输入目标环境的副本数比例,比例数仅支持【0.25、0.3、0.5、0.75】: " rs_number case ${rs_number} in 0.2|0.3|0.5|0.75) cd ${scripts_path} cat prod.txt | grep -vE "apollo|NAMESPACE|kube-system|auth-center" | 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` if [ ${rs1} == 1 ]||[ ${rs1} == 2 ];then su - ${env_dest} -c "kubectl scale --replicas=${rs1} deploy/${dm} -n ${ns}" #echo "su - ${env_dest} -c kubectl scale --replicas=${new_rs} deploy/${dm} -n ${ns}" else new_rs=`awk -v a=${rs2} 'BEGIN{print(int(a)==(a))?int(a):int(a)+1}'` if [ ${new_rs} -le 2 ];then su - ${env_dest} -c "kubectl scale --replicas=2 deploy/${dm} -n ${ns}" #echo "su - ${env_dest} -c kubectl scale --replicas=2 deploy/${dm} -n ${ns}" else su - ${env_dest} -c "kubectl scale --replicas=${new_rs} deploy/${dm} -n ${ns}" #echo "su - ${env_dest} -c kubectl scale --replicas=${new_rs} deploy/${dm} -n ${ns}" fi fi done echo "已更新完成!!!";; *) echo "您输入的副本数比例不符合要求,请重新运行脚本或联系管理员【dongwu】" exit;; esac