Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the number of CPU cores shown to a pod

Tags:

kubernetes

containers[].resources.limits.cpu can limit CPU resources for a pod like:

spec:
  containers:
  - name: cpu-demo-ctr
    image: vish/stress
    resources:
      limits:
        cpu: "1"
      requests:
        cpu: "0.5"

I'd also like to set the number of CPU cores shown to a pod. Is it possible?

like image 406
kawty Avatar asked Aug 02 '18 02:08

kawty


People also ask

How many cores does a Kubernetes pod have?

It will instead be scheduled to first node, since it has 2 cores.

How do I know how many cpus are in Kubernetes?

This would ideally be the sum of all container requests in a cluster. This value at node level can be retrieved by running kubectl describe node <node-name> command. We used to sum up these values to get total allocated cpu in a cluster.

How much CPU is a pod using?

Each container has a limit of 0.5 CPU and 128MiB of memory. You can say the Pod has a request of 0.5 CPU and 128 MiB of memory, and a limit of 1 CPU and 256MiB of memory.


1 Answers

As detailed in documentation here the 1 cpu in is equivalent to:

  • 1 AWS vCPU
  • 1 GCP Core
  • 1 Azure vCore
  • 1 Hyperthread on a bare-metal Intel processor with Hyperthreading

So you can request a core using

cpu: "1"

or

cpu: "1000m"

But if you want to be more precise - you can allocate like 250m of a CPU:

cpu: "250m"

Lastly, if you need more than one cpu you could do:

cpu: "2"
like image 114
Vishal Biyani Avatar answered Nov 15 '22 09:11

Vishal Biyani