停止放大或缩小之前,在StatefulSet中停止所有Pod [英] Stop all Pods in a StatefulSet before scaling it up or down

查看:56
本文介绍了停止放大或缩小之前,在StatefulSet中停止所有Pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队目前正在将Discord聊天机器人迁移到Kubernetes.我们计划将 StatefulSet 用于主要的bot服务,因为每个碎片(吊舱)只能与网关建立单一连接.每当分片连接到所述网关时,它都会告诉它其ID(在我们的情况下为Pod的序号索引)和我们总共运行了多少个分片(StatefulSet中副本的数量).

必须告知网关分片的总数,这意味着要缩放StatefulSet的大小,请我们必须先停止该StatefulSet中的所有Pod,然后再开始使用更新后的值

我该如何实现?最好通过配置,这样我就不必每次都运行特殊命令.

解决方案

一种方法是, 首先通过运行以下命令获取StatefulSets的YAML配置并将其保存在文件中:

kubectl get statefulset NAME -o yaml > sts.yaml

然后通过运行以下命令删除StatefulSet:

kubectl delete -f sts.yaml

最后,再次使用第一步中获得的相同配置文件创建StatefulSet.

kubectl apply -f sts.yaml

我希望这能回答您的查询,以便仅删除StatefulSets并创建新的StatefulSets.

My team is currently working on migrating a Discord chat bot to Kubernetes. We plan on using a StatefulSet for the main bot service, as each Shard (pod) should only have a single connection to the Gateway. Whenever a shard connects to said Gateway, it tells it its ID (in our case the pod's ordinal index) and how many shards we are running in total (the amount of replicas in the StatefulSet).

Having to tell the gateway the total number of shards means that in order to scale our StatefulSet up or down we'd have to stop all pods in that StatefulSet before starting new ones with the updated value.

How can I achieve that? Preferrably through configuration so I don't have to run a special command each time.

解决方案

One way of doing this is, Firstly get the YAML configuration of StatefulSets by running the below command and save it in a file:

kubectl get statefulset NAME -o yaml > sts.yaml

And then delete the StatefulSets by running the below command:

kubectl delete -f sts.yaml

And Finally, again create the StatefulSets by using the same configuration file which you got in the first step.

kubectl apply -f sts.yaml

I hope this answers your query to only delete the StatefulSets and to create the new StatefulSets as well.

这篇关于停止放大或缩小之前,在StatefulSet中停止所有Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆