简体   繁体   English

根据连接的用户数在Kubernetes中自动缩放Pod

[英]Auto-scaling pods in Kubernetes depending on number of connected users

In order to practice scaling using Kubernetes, I have created the following scenario: 为了练习使用Kubernetes进行扩展,我创建了以下场景:


The Game: 游戏:

  • I have a game written in Java which has 2 players, a master (chooses a number below 100) and a guesser (tries to guess the number). 我有一个用Java编写的游戏,有2个玩家,一个大师(选择一个低于100的数字)和一个猜测器(尝试猜测这个数字)。
  • The server-instance terminates once the guesser has correctly guessed the number, or one of the players disconnects. 一旦猜测者正确猜测了该数字,或者其中一名玩家断开连接,服务器实例即终止。
  • Every server-instance only allows for a maximum of 2 connections (master, guesser). 每个服务器实例最多只允许2个连接(主服务器,猜测器)。

Kubernetes: Kubernetes:

  • Whenever the server is reaches it maximum connections, I want Kubernetes to automatically start another server-instance and use that new server-instance for new users that connect. 每当服务器达到最大连接数时,我都希望Kubernetes自动启动另一个服务器实例,并将新的服务器实例用于连接的新用户。

My idea was to use Kubernetes-Client from the Java server-instance, and update the Kubernetes cluster from each server-instance. 我的想法是使用Java服务器实例中的Kubernetes-Client ,并从每个服务器实例中更新Kubernetes集群。 In this form, I would have a decentralized way of managing the cluster. 以这种形式,我将有一种分散的方式来管理集群。

What are your thoughts on this? 您对此有何想法? Is there a better way to approach this? 有没有更好的方法来解决这个问题? Could I for example update metadata on the pod and use some form of auto-scaling for this? 例如,我可以更新吊舱上的元数据并为此使用某种形式的自动缩放吗?

You probably want to use the cluster autoscaler functionality of kubernetes. 您可能要使用kubernetes的集群自动缩放功能。 Please refer to the docs . 请参考文档

Your approach of using a fixed user number as a custom metric will probably work, but maybe you are better off using generic metrics, such as the CPU consumption on your node. 使用固定用户号码作为自定义指标的方法可能会起作用,但是使用通用指标(例如节点上的CPU消耗)可能会更好。 For that you define the maximal consumption that your containers are allowed to use. 为此,您可以定义允许您的容器使用的最大消耗量。 This information is required by the autoscaler to know if it can schedule additional pods on a node. 自动缩放器需要此信息,以了解它是否可以在节点上调度其他容器。

Note that there are two layers of scalability to consider. 注意,要考虑两层可伸缩性。 The pods and the nodes. 吊舱和节点。 The autoscaler will take the metric you define and schedule additional pods when required. 自动缩放器将采用您定义的指标,并在需要时安排其他容器。 Your nodes will have limited capacity for the number of pods, so now, depending on the underlying infrastructure you use, you also need to scale the number of worker nodes. 您的节点的Pod数量容量有限,因此,现在,根据您使用的基础基础架构,您还需要扩展辅助节点的数量。 For example if you run on AWS you need an Autoscale group. 例如,如果您在AWS上运行,则需要一个Autoscale组。 The best way to set this up is to have the AWS Autoscale group scale up based on queued up, scheduled pods. 进行此设置的最佳方法是让AWS Autoscale组根据排队的预定Pod进行扩展。 So whenever there are pods in the queue that cannot be scheduled your Autoscale group will add another node. 因此,只要队列中有无法计划的Pod,您的Autoscale组就会添加另一个节点。 Here is a great article that explains it. 这是一篇很好的文章 ,对其进行了解释。

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

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