K8S一键停起副本数

cat start_k8s.sh
#!/bin/bash

for i in `cat /tmp/replicas.txt`;do kubectl scale deployment `echo $i | awk -F ":" '{print $2}'` -n `echo $i | awk -F ":" '{print $1}'` --replicas `awk -F ":" '{print $3}'`;done >/tmp/k8s_start.log
exit 0

cat stop_k8s.sh
#!/bin/bash
kubectl get deployment -A | egrep -v "monitoring|elk|kafka|apollo|kube-system|0/0" | awk '{print $1":"$2":"$5}' | sed '1d' >/tmp/replicas.txt
for i in `cat /tmp/replicas.txt`;do kubectl scale deployment `echo $i | awk -F ":" '{print $2}'` -n `echo $i | awk -F ":" '{print $1}'` --replicas 0;done >/tmp/k8s_stop.log

exit 0

 

posted @ 2021-09-30 16:52  缺个好听的昵称  阅读(49)  评论(0编辑  收藏  举报