CPU Unit in Kubernetes

CPU Unit in Kubernetes

In this article, we are going to discuss the CPU unit that is used in Kubernetes. Following is the example of adding CPU resource requests and limits in a typical Kubernetes deployment.

    resources:
      requests:
        cpu: "250m"
      limits:
        cpu: "500m"

But what does 250m mean in terms of CPU utilization? Let's look at what this unit of measurement means.

Linux operating system thinks about the CPU in terms of time and not core. According to Kubernetes docs, 1 CPU Core = 1000m. Notation m stands for milliCPU.

Also according to docs: 10m = 1 ms Therefore: 1000m = 100 ms Here notation ms denotes the actual CPU execution time.

So when we request 10m CPU we are basically asking the Linux kernel to allocate 1 ms of execution time for every 100 ms of CPU execution time.

If the CPU request is 500m, we are requesting (500m / 1000m) * 100ms = 50 ms execution time for every 100 ms of CPU execution time, which is 50% of the total CPU execution time.

There is a great video that explains this same concept from KubeCon 2022 link.