如何基于负载自动缩放kubernates中的弹性搜索? [英] How to autoscale elastic search in kubernates based on load?

查看:52
本文介绍了如何基于负载自动缩放kubernates中的弹性搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Cloud,并且正在做RnD,是否可以在Kubernetes中的Elasticsearch上应用HPA(水平Pod自动缩放).

I am using Google Cloud and I am doing RnD whether we can apply HPA (Horizontal Pod Auto scaling) on elasticsearch in Kubernetes.

我在Kubernetes上进行了elasticsearch设置: https://github.com/elastic/helm-charts/tree/master/elasticsearch

但是我在论坛上发现了一篇帖子,他们说elasticsearch HPA很难

But I found one of the post on forum they say elasticsearch HPA is hard

https://discuss.elastic.co/t/how-to-scale-up-and-down-nodes-automatically/224089/2

那么是否可以对elasticsearch进行HPA?

So is it possible to do HPA on elasticsearch or not ?

推荐答案

我认为它不能很好地工作,并且您可能会丢失数据. HPA趋向于在大约一分钟左右的时间内对负载变化做出响应,并且偶尔会做出较大的变化(例如,从5个副本缩放到2个副本).对于Elasticsearch,您需要一次扩展一个节点,监视集群的状态然后才能继续进行,从一个节点移到下一个节点可能要花费很长时间.

I don't think it would work well and you'd be at risk of losing data. HPA tends to respond to load changes on a scale of a minute or so, and can occasionally make large changes (scaling from 5 replicas to 2, for example). For Elasticsearch you need to scale in one node at a time, monitor the state of the cluster before you can proceed, and it could take a long time before you can move from one node to the next.

假设您正在StatefulSet中运行Elasticsearch.请记住,每个ES索引都是由 shards 组成的;您将拥有一定数量的分片副本,这些副本分布在ES群集中​​的各个节点上.因此,也可以说您的索引有10个分片,每个分片2个副本.

Say you're running Elasticsearch in a StatefulSet. Remember that each ES index is made up of shards; you will have some number of copies of the shards spread out across the nodes in the ES cluster. So also let's say your index has 10 shards with 2 replicas each.

向外扩展很容易.根据需要增加StatefulSet的大小;配置每个节点以与es-0对话以进行发现. ES将看到群集已增长,并开始将分片自己移动到新节点上.

Scaling out is easy. Increase the size of the StatefulSet as much as you want; configure each node to talk to es-0 for discovery. ES will see that the cluster has grown and start moving shards on to the new nodes on its own.

很难扩大规模.您一次只能删除一个节点.一旦该节点关闭并且集群意识到它丢失了,那么该节点上曾经存在的分片将被复制不足. ES将在其余节点上创建新副本,并在其中复制分片数据.您可以通过 /_cat/shards API .索引状态将为黄色".只要存在复制不足的分片,然后将切换回绿色"分片.复制序列完成后.

Scaling in is hard. You can only delete one node at a time. Once that node is shut down and the cluster realizes it's missing, then the shards that used to be on that node will be under-replicated. ES will create new replicas on the remaining nodes and copy the shard data there. You can observe this happening through things like the /_cat/shards API. The index status will be "yellow" as long as there are under-replicated shards, and then will switch back to "green" once the replication sequence finishes.

因此,假设您当前有8个节点,并且您希望缩小到6个节点.给定分片的两个副本有可能位于es-6es-7上,因此您不能同时关闭这两个副本一起;您必须先关闭es-7,等待复制赶上,然后再关闭es-6.还有一种可能,当您关闭es-7时,新副本将在注定失败的节点es-6上创建.

So say you currently have 8 nodes, and you want to scale down to 6. There's some possibility the only two replicas of a given shard will be on es-6 and es-7 so you can't turn those both off together; you have to turn off es-7 first, wait for replication to catch up, then turn off es-6. There's also some possibility that, when you turn off es-7, the new replicas will be created on the doomed node es-6.

您还可以告诉Elasticsearch在删除副本之前将其从副本中移出.这避免了集群进入黄色"状态.状态,但更难监控.

You can also tell Elasticsearch to move shards off of a replica before removing it. This avoids the cluster going into the "yellow" state, but it's harder to monitor.

最后,根据集群中实际有多少数据,重新复制可能会花费很长时间. (在我以前使用错误设计的索引结构维护的群集中,关闭节点花了多个小时.)这比HPA准备的操作要慢得多.

Finally, the re-replication can take a long time depending on how much data is actually in the cluster. (In a past cluster I maintained with a badly-designed index structure, it took multiple hours to shut down a node.) That's a much slower operation than HPA is prepared for.

这篇关于如何基于负载自动缩放kubernates中的弹性搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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