k8s replicaset数量扫描

#!/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}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值