k8s中如果一定要重启某个namespace下所有微服务,分奇行、偶行重启,尽量减小对业务的影响。
$ cat restart_all_microservice_k8s.sh
#!/bin/bash
ns="test"
#奇数行
pods=`kubectl get po -n ${ns} | awk '{print$1}' | grep -v NAME | sed -n '1~2p'`
for pod in $pods
do
echo "kubectl delete pod -n ${ns} $pod"
nohup kubectl delete pod -n ${ns} $pod &
echo ""
sleep 3
done
#偶数行
pods=`kubectl get po -n ${ns} | awk '{print$1}' | grep -v NAME | sed -n '0~2p'`
for pod in $pods
do
echo "kubectl delete pod -n ${ns} $pod"
nohup kubectl delete pod -n ${ns} $pod &
echo ""
sleep 3
done
网友评论