Kubernetes容器自动伸缩

3

是否可以在Kubernetes中自动扩展包含应用服务器(例如wildfly/tomcat/jetty)的Docker容器?例如根据CPU和内存使用情况或基于HTTP请求?如果有内置功能,我找不到它,或者是否可以编写类似配置脚本以实现此功能?如果可以,魔法发生在哪里?

4个回答

4

目前容器的自动扩展还不支持,并且也不在 Kubernetes 近期 1.0 路线图 的计划中(这意味着核心团队不会很快添加它,但外部贡献肯定是受欢迎的)。


1
作为后续,如果您能够检测到需要扩展的情况(例如您提到的CPU/RAM使用情况),那么执行命令进行扩展就是微不足道的。kubectl resize rc <container_name> --replicas=<new_amount> - aronchick

2
您可以在 Kubernetes 1.3 及以上版本中使用水平 Pod 自动缩放功能。Kubernetes 博客提供了有关此功能的详细信息。

http://blog.kubernetes.io/2016/07/autoscaling-in-kubernetes.html

但是上面的文章主要集中在GKE上,所以下面的内容会更加有用。

https://kubernetes.io/docs/user-guide/horizontal-pod-autoscaling/

这里描述了如何使用 kubectl 进行 Pod 自动缩放。
 kubectl autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]

例子
# Auto scale a deployment "foo", with the number of pods between 2 and 10, target CPU utilization specified so a default autoscaling policy will be used:
  kubectl autoscale deployment foo --min=2 --max=10

  # Auto scale a replication controller "foo", with the number of pods between 1 and 5, target CPU utilization at 80%:
  kubectl autoscale rc foo --max=5 --cpu-percent=80

1
自 Kubernetes 1.2 版本以来,自动缩放已成为稳定 API 的一部分。它基于 CPU 使用情况或容器本身提供的指标进行操作。
可以将其用于如下的部署或副本控制器:
# Auto scale a deployment "foo", with the number of pods between 2 and 10, target CPU utilization specified so a default autoscaling policy will be used:
kubectl autoscale deployment foo --min=2 --max=10

# Auto scale a replication controller "foo", with the number of pods between 1 and 5, target CPU utilization at 80%:
kubectl autoscale rc foo --max=5 --cpu-percent=80

更多详细信息可以在 水平扩展 描述中的官方文档、kubectl autoscale 文档以及 官方博客 中找到。


0
您可以使用水平 Pod 自动缩放器来自动缩放部署。
 kubectl autoscale deployment task2deploy1 –cpu-percent=80 –min=2 –max=6

命令将确保部署至少有2个和最多6个 pod,目标 CPU 利用率设置为 80%。 您可以使用以下命令列出自动缩放器:
 kubectl get hpa

名称 引用 目标 最小Pod数 最大Pod数 副本
task2deploy1 Deployment/task2deploy1 /80% 2 6 0

 kubectl describe  hpa 

名称: task2deploy1

屏幕上将打印有关自动缩放器的大量信息。

使用以下内容继续检查 Pod 数量的更改:

kubectl describe deployment task2deploy1 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接