简体   繁体   English

Kafka/Kubernetes 和 Autoscale

[英]Kafka/Kubernetes and Autoscale

I have a question about Kafka in Kubernetes, specially autoscaling...我在 Kubernetes 中有一个关于 Kafka 的问题,特别是自动缩放...

Let say I have 3 Kafka Brokers in 3 Pods in Kubernetes and there is a TopicA with 5 partitions (P1, P2, P3, P4, P5) and replication factor is 3 and all Brokers have their Persistent Volumes and I have auto scaling in Kubernetes configured so if it detects, lets say %80 CPU/Memory usage in Kafka Pods it will starts additional Pods for Kafka Brokers...假设我在 Kubernetes 的 3 个 Pod 中有 3 个 Kafka 代理,并且有一个带有 5 个分区(P1、P2、P3、P4、P5)的 TopicA,复制因子为 3,所有代理都有它们的持久卷,我在 Z30136395F01879792198317C18EA41 中具有自动缩放功能配置,因此如果它检测到,假设 Kafka Pod 中的 CPU/内存使用率为 %80,它将为 Kafka Brokers 启动额外的 Pod...

If I am not completely wrong, Kafka will detect over Zookeeper extra instances and can shift Partitions (so lets say P1, P2 were at Broker1 and P3, P4 were at Broker2 and P5 was at Broker3) so a new Pod comes the picture I will expect would be something like following P1 at Broker1, P3, P4 Broker2, P5 Broker3 and P2 at Broker4.如果我没有完全错,Kafka 将检测到 Zookeeper 的额外实例并可以转移分区(假设 P1、P2 在 Broker1 和 P3,P4 在 Broker2 和 P5 在 Broker3)所以一个新的 Pod 出现在我的图片中期望类似于在 Broker1 处关注 P1、P3、P4 Broker2、P5 Broker3 和在 Broker4 处关注 P2。

So my first question is, are the above assumptions correct and Kafka behave like this or not?所以我的第一个问题是,上述假设是否正确,卡夫卡的行为是否如此?

Second question is about down scaling, lets load peak is gone and we don't need Pod4, can Kubernetes shotdown the Pod and Kafka can return to the 3 Brokers configuration, that is the part I am not sure of.第二个问题是关于缩减规模,让负载峰值消失,我们不需要 Pod4,Kubernetes 可以击落 Pod 并且 Kafka 可以返回 3 Brokers 配置,这是我不确定的部分。 While I have replication factor 3, 2 other brokers should be able to continue to work, kann Kafka pull Partition P2 to Broker 1 or 2 or 3?虽然我的复制因子为 3,但其他 2 个代理应该能够继续工作,kann Kafka 将分区 P2 拉到代理 1 或 2 或 3?

And the final question would be, if the Kubernetes spawned Pod5,6,7 can we downscale to 3 Pods configuration again?最后一个问题是,如果 Kubernetes 产生 Pod5、6、7,我们能否再次缩减到 3 个 Pod 配置?

Thx for answers..谢谢回答..

Kafka will detect over Zookeeper extra instances and can shift Partitions Kafka 将检测到 Zookeeper 的额外实例并可以转移分区

Partitions will not be rebalanced when expanding a cluster.扩展集群时不会重新平衡分区。

In the case of downscale, partitions must be moved off the brokers before they can be removed from the cluster, otherwise you'll have permanently offline partitions that cannot replicate.在缩减规模的情况下,必须先将分区从代理中移出,然后才能从集群中删除,否则您将拥有无法复制的永久离线分区。 And you need to be conscious of disk utilization when shrinking a cluster as a partition is limited in size by the smallest data directory并且在缩小集群时需要注意磁盘利用率,因为分区的大小受最小数据目录的限制

Kubernetes itself won't help Kafka perform these operations and in non-k8s environments, this process is mostly manual but can be scripted (see kafka-kit by Datadog). Kubernetes 本身不会帮助 Kafka 执行这些操作,并且在非 k8s 环境中,此过程主要是手动的,但可以编写脚本(参见 Datadog 的 kafka-kit)。 I believe that the k8s operators such as Strimzi operator could make data rebalances easier when scaling, however at the time of this answer, it doesn't support automatic reassignment, as per what I see in the docs我相信诸如 Strimzi 运算符之类的 k8s 运算符可以在扩展时使数据重新平衡更容易,但是在这个答案的时候,它不支持自动重新分配,正如我在文档中看到的那样

Strimzi 0.18.0 now natively supports Cruise Control, which means that you can fully perform automate the rebalancing process, including partition reassignment! Strimzi 0.18.0 现在原生支持 Cruise Control,这意味着您可以完全自动执行重新平衡过程,包括分区重新分配!

https://strimzi.io/blog/2020/06/15/cruise-control/ https://strimzi.io/blog/2020/06/15/cruise-control/

Now you can properly autoscale Kafka in Kubernetes:)现在您可以在 Kubernetes 中正确地自动缩放 Kafka :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM