简体   繁体   English

如何在Kubernetes中增加PODS

[英]How to increase PODS in Kubernetes

I'm very new to Kubernetes, I have deployed a cluster on Kubernetes.我对 Kubernetes 很陌生,我已经在 Kubernetes 上部署了一个集群。 Created a deployment and set POD's count to 2. I didn't create HPA for this deployment.创建了一个部署并将 POD 的计数设置为 2。我没有为此部署创建 HPA。

I'm using Google Cloud for this.为此,我正在使用 Google Cloud。 I enabled autoscaling for the cluster.我为集群启用了自动缩放。 min is 2 and max is 30.最小值为 2,最大值为 30。

I got the OOMKilled error in my deployment.我在部署中遇到了OOMKilled错误。

So the question is所以问题是

So only HPA can increase/decrease PODS count am I right ??.所以只有 HPA 可以增加/减少 PODS 数量,对吗??。 In that case, HPA based on memory and CPU is a must and should for every deployment.在这种情况下,基于内存和 CPU 的 HPA 是每个部署都必须和应该的。

Please correct me if I'm wrong.如果我错了,请纠正我。

You can use kubectl to change the number of pods running:您可以使用kubectl更改正在运行的 pod 数量:

kubectl scale deployment <DEPLOYMENT NAME> --replicas=<#PODS>
kubectl scale deployment student-app --replicas=2

You can find more info at the docs page您可以在文档页面找到更多信息

Not really, OOM can be a complex issue inside your application that has nothing to do with scaling.并非如此,OOM 可能是应用程序内部的一个复杂问题,与扩展无关。 Imagine you have a mem leak in your long running application.想象一下,您的长时间运行的应用程序中存在内存泄漏。 If the only thing you do is scaling to more pods, you'll end up just consuming more and more resources, and still running into OOM Kills on your pods.如果您所做的唯一一件事就是扩展到更多 Pod,那么最终只会消耗越来越多的资源,并且仍然会在 Pod 上遇到 OOM Kills。

The real solution is to have a predictable memory consumption patterns inside your applications.真正的解决方案是在您的应用程序中拥有可预测的内存消耗模式。

Imagine an app that can use up to 64 Mb ram, but in some very rare case it can jump up to 256... well, then you need to give it 256. What if this app is running in multi-process/thread environment running N workers (ie. php-fpm) now it max mem usage is Nx256 in peaks (this is why it makes sense in many cases not to run pools of many processes in container, but scale them with HPA instead).想象一个应用程序最多可以使用 64 Mb ram,但在一些非常罕见的情况下它可以跳到 256 ......好吧,那么你需要给它 256。如果这个应用程序运行在多进程/线程环境中会怎样运行 N 个工人(即 php-fpm)现在它的最大内存使用量在峰值时为 Nx256(这就是为什么在许多情况下不在容器中运行多个进程的池,而是使用 HPA 扩展它们是有意义的)。

In the end, your memory requests/limits for a POD need to be what the application inside needs, so profiling an app, and designing it for predictability is the solution here.最后,您对 POD 的内存请求/限制需要满足内部应用程序的需求,因此分析应用程序并为其设计可预测性是这里的解决方案。

And finaly, yes, if you need to scale a deployment (up/down) just use kubectl scale最后,是的,如果您需要扩展部署(向上/向下),只需使用kubectl scale

You are correct that HPA's are pod specific.您是正确的,HPA 是特定于 pod 的。 I would not say that it is a requirement for every deployment.我不会说这是每个部署的要求。 For instance MySQL just happens to be really good at hanging on to memory, and typically applications that are written well might spike to 100% cpu while performing worker jobs.例如,MySQL 恰好非常擅长保留内存,通常编写良好的应用程序在执行工作任务时可能会飙升至 100% 的 CPU。 I think it really just depends on the application.我认为这真的只取决于应用程序。 L7 load balancers for instance, scale on cpu or drop packets.例如,L7 负载平衡器可扩展 CPU 或丢弃数据包。

Cluster scaling, however, is based on the resources block of the pod spec, specifically resource requests.然而,集群扩展基于 pod 规范的资源块,特别是资源请求。 Kubernetes monitors the amount of resource requests each pod on a node makes to determine how full that node is. Kubernetes 监控节点上每个 Pod 发出的资源请求量,以确定该节点的满载情况。 If all nodes are full and there is a pod that is pending scheduling a new node is created.如果所有节点都已满并且有一个 pod 正在等待调度,则会创建一个新节点。

Application developers need to not allocate memory that they do not have.应用程序开发人员不需要分配他们没有的内存。 If you are getting OOM killed the application is written in a way to assume that it will be able to alloc.如果您被 OOM 杀死,则应用程序的编写方式假定它将能够分配。 When you write an application running inside of a docker container I believe these limits are visible to you and set by cgroups.当您编写在 docker 容器内运行的应用程序时,我相信这些限制对您是可见的,并且由 cgroups 设置。 Resource Limits can kill your container once it reaches some specified limits as well, I'm just not sure that this would display as OOM killed.一旦达到某些指定的限制,资源限制也可以杀死您的容器,我只是不确定这是否会显示为 OOM 已终止。

In my experience Resource Requests are something that should be provided in almost every deployment so that cluster scaling works correctly.根据我的经验,几乎每个部署都应该提供资源请求,以便集群扩展正常工作。

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

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