<p>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%.</p>
<p>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).</p>
<p>I am wondering if this way is right? otherwise, is there the best other way to decide the limit of cpu?</p>

<p>To answer your question, <code>I am wondering if this way is right?</code>, yes, that's the right way. You can also use a tool called <a href="https://github.com/FairwindsOps/goldilocks" rel="nofollow noreferrer">goldilocks</a>, 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.</p>
<hr />
<p>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”.</p>
<p>So if you want 30% of 1 of your cores then <code>300m</code> is the correct amount. But if you want 30% of your 4 cores, then I would say <code>1200m</code> is the correct amount.</p>
<p>There is kubernetes <a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu" rel="nofollow noreferrer">documentation</a> about that.</p>
<hr />
<p>You could also consider using <a href="https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler" rel="nofollow noreferrer">Vertical Pod Autoscaler</a>.</p>
<blockquote>
<p>Vertical Pod Autoscaler (VPA) <strong>frees the users from necessity of setting up-to-date resource limits and requests</strong> for the containers in their pods. When configured, <strong>it will set the requests automatically based on usage</strong> and thus allow proper scheduling onto nodes so that appropriate resource amount is available for each pod. <strong>It will also maintain ratios between limits and requests that were specified in initial containers configuration.</strong></p>
</blockquote>
<hr />
<p>I would also recommend to read below tutorials about limits and requests:</p>
<ul>
<li><a href="https://learnk8s.io/setting-cpu-memory-limits-requests" rel="nofollow noreferrer">Setting the right requests and limits in Kubernetes</a></li>
<li><a href="https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-resource-requests-and-limits" rel="nofollow noreferrer">Kubernetes best practices: Resource requests and limits</a></li>
</ul>
