Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of CPU and core in Kubernetes?

Tags:

kubernetes

I don't really understand this after reading through the document. Some use a term like "CPU", but some use "core".

I am running Kubernetes in my laptop for testing purpose. My laptop has one CPU (2.2 GHz) and four cores.

If I want to set the CPU request/limit for pod, should the maximum resource that I have be 1000m or 4000m?

What is the difference (CPU vs. core) here in a Kubernetes context?

like image 926
Sam YC Avatar asked Nov 12 '18 04:11

Sam YC


People also ask

What is CPU core in Kubernetes?

In Kubernetes, 1 CPU unit is equivalent to 1 physical CPU core, or 1 virtual core, depending on whether the node is a physical host or a virtual machine running inside a physical machine. Fractional requests are allowed. When you define a container with spec.

What does 1000m CPU mean?

CPU resources are measured in millicore. If a node has 2 cores, the node's CPU capacity would be represented as 2000m. The unit suffix m stands for “thousandth of a core.” 1000m or 1000 millicore is equal to 1 core. 4000m would represent 4 cores.

What does CPU 100m mean?

memory: 100Mi. cpu: 100m. The unit suffix m stands for “thousandth of a core,” so this resources object specifies that the container process needs 50/1000 of a core (5%) and is allowed to use at most 100/1000 of a core (10%).

How many cores does a Kubernetes pod have?

It will instead be scheduled to first node, since it has 2 cores. The K8S documentation is a bit vague on this but it states: "A Container might or might not be allowed to exceed its CPU limit for extended periods of time.


2 Answers

To clarify what's described here in the Kubernetes context, 1 CPU is the same as a core (Also more information here).

1000m (milicores) = 1 core = 1 vCPU = 1 AWS vCPU = 1 GCP Core.
100m (milicores) = 0.1 core = 0.1 vCPU = 0.1 AWS vCPU = 0.1 GCP Core.

For example, an Intel Core i7-6700 has four cores, but it has Hyperthreading which doubles what the system sees in terms of cores. So in essence, it will show up in Kubernetes as:

8000m = 8 cores = 8 vCPUs

Some extra information: These resources are managed by the kube-scheduler using the Completely Fair Scheduler (CFS), and there are no guarantees in terms of overruns within the same machine and your pod may be moved around.

If you'd like to have stronger guarantees, you might consider the --cpu-manager-policy=static (CPU Manager) option in the kubelet. More information is here and here.

For more details on what your system sees as a CPU (and number of CPUs) on a Linux system you can see how many vCPUs you have by running cat /proc/cpuinfo.

like image 94
Rico Avatar answered Oct 04 '22 03:10

Rico


To remove any guesswork regarding your laptop or any other environment, execute:

kubectl get nodes

...and then this for a particular node:

kubectl describe node <node-name>

Look for cpu under Allocatable (which may have the same value as under 'Capacity').

Take into consideration that

1 CPU = 1000 millicores/millicpu

when setting "fractional" resources.requests.cpu and resources.limits.cpu for containers.

like image 23
apisim Avatar answered Oct 04 '22 04:10

apisim