kubernetesspringcloud收藏

【k8s】k8s重启某个namespace下所有微服务

2022-03-21  本文已影响0人  Bogon

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
上一篇下一篇

猜你喜欢

热点阅读