What size should the cpu limits be decided in k8s?

4/5/2021

I did performance test to my application. The usage of cpu was 30% while testing. - the test sever has 4 cores. so I thought one core had 30/4 usage = 7.5%.

I want to a container in k8s to keep the usage of CPU under 30% so I decided that the cpu limits was 250m + 50m(extra core).

I am wondering if this way is right? otherwise, is there the best other way to decide the limit of cpu?

-- seo
cpu
kubernetes
limit

1 Answer

4/7/2021

To answer your question, I am wondering if this way is right?, yes, that's the right way. You can also use a tool called goldilocks, a kubernetes controller that collects data about running pods and provides recommendations on how to set resource requests and limits. It could help you identify a starting point for resource requests and limits.


I'm not sure if your calculations are correct, as CPU resources are defined in millicores. If your container needs two full cores to run, you would put the value “2000m”. If your container only needs ¼ of a core, you would put a value of “250m”.

So if you want 30% of 1 of your cores then 300m is the correct amount. But if you want 30% of your 4 cores, then I would say 1200m is the correct amount.

There is kubernetes documentation about that.


You could also consider using 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.


I would also recommend to read below tutorials about limits and requests:

-- Jakub
Source: StackOverflow