美文网首页kubernetesspringcloud收藏
【k8s】k8s重启某个namespace下所有微服务

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

作者: Bogon | 来源:发表于2022-03-21 00:01 被阅读0次

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

相关文章

网友评论

    本文标题:【k8s】k8s重启某个namespace下所有微服务

    本文链接:https://www.haomeiwen.com/subject/qwlzdrtx.html