在 k8s 中应该决定 cpu 限制的大小是多少?

What size should the cpu limits be decided in k8s?

我对我的应用程序进行了性能测试。 测试时 cpu 的使用率为 30%。 - 测试服务器有 4 个核心。 所以我认为一个核心的使用率为 30/4 = 7.5%。

我想在 k8s 中创建一个容器,以将 CPU 的使用率保持在 30% 以下 所以我决定 cpu 限制为 250m + 50m(额外核心)。

请问这种方式对不对?否则,有没有其他最好的方法来决定 cpu 的极限?

回答你的问题,I am wondering if this way is right?,是的,这是正确的方法。您还可以使用名为 goldilocks 的工具,这是一个 kubernetes 控制器,它收集有关 运行ning pods 的数据,并提供有关如何设置资源请求和限制的建议。它可以帮助您确定资源请求和限制的起点。


我不确定您的计算是否正确,因为 CPU 资源是以毫核为单位定义的。如果您的容器需要两个完整的核心才能 运行,您可以将值设置为“2000m”。如果您的容器只需要 ¼ 个核心,您可以输入“250m”的值。

因此,如果您想要 1 个核心的 30%,那么 300m 是正确的数量。但是如果你想要 4 个核心的 30%,那么我会说 1200m 是正确的数量。

关于那个有 kubernetes documentation


您也可以考虑使用 Vertical Pod Autoscaler

Vertical Pod Autoscaler (VPA) frees the users from necessity of setting up-to-date resource limits and requests for the containers in their pods. When configured, it will set the requests automatically based on usage and thus allow proper scheduling onto nodes so that appropriate resource amount is available for each pod. It will also maintain ratios between limits and requests that were specified in initial containers configuration.


我还建议阅读以下有关限制和请求的教程: