gpt4 book ai didi

mongodb - statefulset 最佳实践的动态扩展

转载 作者:行者123 更新时间:2023-12-02 12:26:06 32 4
gpt4 key购买 nike

背景

我的应用程序使用分片 mongodb 和 elasticsearch statefulsets 在 kubernetes 集群中运行。我在我的应用程序中为部署组件设置了水平 pod 自动缩放器,一切正常。

问题

当流量上升时就会出现问题。我的服务器部署扩展得很好,但 mongodb 分片和 elasticsearch 节点无法处理如此多的流量并限制整体响应时间。

简单的解决方案是为那些有更多分片、更多副本的状态集配置。让我烦恼的是,交通高峰每天会发生 3-4 个小时,因此让所有这些男孩在一天的剩余时间里无所事事地坐着有点浪费。

我做了一些研究,看起来数据库一般不应该动态扩展/缩减,因为它会消耗大量网络和磁盘 io 只是为了在它们之间进行复制。在放大、缩小过程中也存在数据丢失和不一致的可能性。

问题

如果可能,在 mongodb、elasticsearch...和一般数据库中处理动态缩放的正确方法是什么?
如果不是,我该怎么做才能从我的云账单中节省一些美分,因为我们每天只需要短时间内从数据库 pod 获得最大功率。

最佳答案

您应该阅读有关 Kubernetes 自动缩放的信息 - HPA .

The Horizontal Pod Autoscaler automatically scales the number of pods in a replication controller, deployment, replica set or stateful set based on observed CPU utilization (or, with custom metrics support, on some other application-provided metrics). Note that Horizontal Pod Autoscaling does not apply to objects that can't be scaled, for example, DaemonSets.

The Horizontal Pod Autoscaler is implemented as a Kubernetes API resource and a controller. The resource determines the behavior of the controller. The controller periodically adjusts the number of replicas in a replication controller or deployment to match the observed average CPU utilization to the target specified by user.

使用 HPA,您还应该注意卷安装和数据延迟。


正如@Serge 在评论中提到的,我建议检查 MongoDB 和 Elasticsearch 本身提供的原生扩展集群选项。

看看

我不是很熟悉 MongoDB 和 Elasticsearch with Kubernetes,但也许这些教程对你有帮助:


如果您使用 helm看看banzaicloud Horizontal Pod Autoscaler operator

You may not want nor can edit a Helm chart just to add an autoscaling feature. Nearly all charts supports custom annotations so we believe that it would be a good idea to be able to setup autoscaling just by adding some simple annotations to your deployment.

We have open sourced a Horizontal Pod Autoscaler operator. This operator watches for your Deployment or StatefulSet and automatically creates an HorizontalPodAutoscaler resource, should you provide the correct autoscale annotations.


希望你觉得这很有用。

关于mongodb - statefulset 最佳实践的动态扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63070247/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com