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?
As mentioned in Edit This Page Assign CPU Resources to Containers and Pods, it clearly says that:
The CPU resource is measured in CPU units. One CPU, in Kubernetes, is equivalent to:
- 1 AWS vCPU
- 1 GCP Core
- 1 Azure vCore
- 1 Hyperthread on a bare-metal Intel processor with Hyperthreading
So, setting argument -cpus "2"
tells the container to attempt to use two CPUs.
Also, CPU is always requested as an absolute quantity, never as a relative quantity; 0.1 is the same amount of CPU on a single-core, dual-core, or 48-core machine.
To clarify what's described here in the Kubernetes context, 1 CPU is the same as a core.
1000m (milicores) = 1 core = 1 CPU = 1 AWS vCPU = 1 GCP Core.
100m (milicores) = 0.1 core = 0.1 CPU = 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 CPUs
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.
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.
I personally think that the apisim solution is more suitable for my problem.
I run the commands and find out I only have two allocatable cores:
I couldn't understand why until I found this:
Rico is right about my laptop should have eight cores due to hyper-threading. But the Docker default settings throttle it to two.