> For the complete documentation index, see [llms.txt](https://amartyushov.gitbook.io/tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://amartyushov.gitbook.io/tech/platforms/kubernetes/pod/resources.md).

# Resources

## Pod CPU resources

[Great article based on which below info is created](https://medium.com/@jettycloud/making-sense-of-kubernetes-cpu-requests-and-limits-390bbb5b7c92). Find inside:

* explanation of CPU resource and limits for k8s Pod
* Prometheus queries to monitor Pod metrics

```
apiVersion: v1
kind: Pod
metadata:
  name: my-app
spec:
  containers:
  - name: app
    image: my.private.registry/my-app
    resources:
      requests:              // we are talking about it
        memory: "64M"
        cpu: "250m"
      limits:
        memory: "128M"
        cpu: "500m"
```

<figure><img src="https://415484505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxtoAXZwwOc4XGto8vb%2Fuploads%2Fc8fu9dTBxx2dyc3HQB4o%2FScreenshot%202023-08-31%20at%2008.53.11.png?alt=media&amp;token=e2f70db7-6a8a-4092-8071-14a7e65ff1a0" alt=""><figcaption></figcaption></figure>

1 CPU Unit = 1024 CPU Shares

Below is how CFS will balance PODs with different CPU Unit resource configuration among cores

<figure><img src="https://415484505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxtoAXZwwOc4XGto8vb%2Fuploads%2F93YoWE9ANCXkpkXww4K7%2FScreenshot%202023-08-31%20at%2008.55.23.png?alt=media&amp;token=8761f15d-4277-4736-9ded-48cb06669677" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
A **CPU requests unit** can be understood as the **percentage of a given CPU period** that is guaranteed to Pod.
{% endhint %}

{% hint style="info" %}
a 750m CPU for a period of 100 ms means that a POD is guaranteed to have 75 ms of CPU time each 100 ms (on one or multiple cores). A 5000m CPU for a period of 1s means that a Pod is guaranteed to have 5s of CPU each 1s (1s on each of 5 cores).
{% endhint %}

It does not mean that if POD uses less resources than it requested, the CPU will remain idle. If another Pod is runnable at that time, CFS will schedule that Pod.

**CPU limit** unit can be understood as the **percentage** of each scheduler CPU period (100 ms) that a Pod cannot exceed. E.g.: ***limit of 750 m CPU means that each 100 ms period POD cannot use more than 75 ms of CPU time***.

**When an application attempts to use more CPU than it is limited to — CFS will throttle it.**

<figure><img src="https://415484505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxtoAXZwwOc4XGto8vb%2Fuploads%2FdMqf5QpwlULyoceiFekB%2FScreenshot%202023-09-01%20at%2010.22.23.png?alt=media&amp;token=951ac839-7e96-42b5-b6bb-79a8715ae61a" alt=""><figcaption></figcaption></figure>
