k8s replicaset数量扫描
#!/bin/bashCURRENT_PATH=$(cd "$(dirname "$0")"; pwd)rm -f /tmp/replicasetrm -f /tmp/replicaset.jsoncp $CURRENT_PATH/list.json /tmp/replicaset.jsonansible -u ec2-user --key-file /home/ec2-user/.ssh/nx2
·
#!/bin/bash
CURRENT_PATH=$(cd "$(dirname "$0")"; pwd)
rm -f /tmp/replicaset
rm -f /tmp/replicaset.json
cp $CURRENT_PATH/list.json /tmp/replicaset.json
ansible -u ec2-user --key-file /home/ec2-user/.ssh/nx2.pem -i /etc/ansible/hosts 172.37.100.71 -m copy -a "src=$CURRENT_PATH/check-replicaset dest=/tmp/"
#ansible -u ec2-user -i /etc/ansible/hosts 173.35.88.71 -m shell -a "sh /tmp/check-org.sh"| grep -v CHANGED | grep -v "sessionAffinity: None" > /tmp/replicaset
ansible -u ec2-user --key-file /home/ec2-user/.ssh/nx2.pem -i /etc/ansible/hosts 172.37.100.71 -m shell -a "sh /tmp/check-replicaset/check.sh" | grep -v CHANGED | grep -v '^$' > /tmp/replicaset
count=$(cat /tmp/replicaset | wc -l)
echo $count
if [ 0 -eq $count ];then
echo "一切正常,无需报警"
exit
fi
cat /tmp/replicaset | while read line ; do deployment=`echo ${line} | awk '{print $2}'` ; sed -i "s#result#${deployment}|result#g" /tmp/replicaset.json ;done
sed -i "s#|result##g" /tmp/replicaset.json
sed -i "s#result##g" /tmp/replicaset.json
cat /tmp/replicaset | while read line ; do detail=`echo ${line} | awk '{print "部署名称:" $2 " 实例数量:" $3}'`;sed -i "s#description#${detail}|description#g" /tmp/replicaset.json ;done
sed -i "s#|description##g" /tmp/replicaset.json
sed -i "s#description##g" /tmp/replicaset.json
curl -H "Content-Type: application/json" -X POST -d @/tmp/replicaset.json http://172.37.66.177:5080/common/alert
##curl -H "Content-Type: application/json" -X POST -d @/tmp/replicaset.json http://192.168.1.40:5080/common/alert
{
"cluster":"poc",
"type": "deployment",
"title": "容器扫描结果:7.lab/poc环境,实例数量需要调整的有:",
"text": "result",
"desc": "description"
}
#! /bin/bash
CURRENT_PATH=$(cd "$(dirname "$0")"; pwd)
rm -f $CURRENT_PATH/{1,2,replicaset-current.list}
kubectl get deployment -owide | grep dmo | awk '{print $1}' | sort | uniq > $CURRENT_PATH/1
for i in $(cat $CURRENT_PATH/1)
do
#判断是否为生产环境
isBeta=$(kubectl get deployment $i -o yaml | grep APPLICATION_TAG -A 1 | grep beta | wc -l)
if [ 0 -eq $isBeta ]; then
env=$(kubectl get deployment $i -o yaml | grep APPLICATION_TAG -A 1)
# echo $env
kubectl get deployment $i -owide | grep dmo | grep "registry.bizsaas.net/service" | awk '{print $7" "$1" "$4}' >> $CURRENT_PATH/2
fi
done
cat $CURRENT_PATH/2 | egrep -v "beta" | awk -F "/|:" '{print $3" "$4}' | awk '{print $1" "$3" "$4}' > $CURRENT_PATH/replicaset-current.list
cat $CURRENT_PATH/replicaset-current.list | while read line
do
APP=""
DEPLOYMENT=""
REPLICASET=0
eval $(echo $line | awk '{printf("APP=%s;DEPLOYMENT=%s;REPLICASET=%d",$1,$2,$3)}')
if [ 1 -eq $REPLICASET ]; then
REPLICASET_RIGHT=0
count=$(grep $APP $CURRENT_PATH/replicaset-1.list | wc -l)
if [ 0 -eq $count ]; then
echo $line
fi
fi
done
#echo "删除过程文件"
#rm -f $CURRENT_PATH/{1,2,replicaset-current.list}
rm -f $CURRENT_PATH/{1,2}
更多推荐
已为社区贡献5条内容
所有评论(0)