others-How to understand the cpu unit in kubernetes?

1. Purpose

In this post, I would show my understanding about the cpu resource unit in kubernetes.

2. Environment

  • Kubernetes

3. The cpu resource unit in Kubernetes?

3.1 What is the cpu unit in kubernetes?

In kubernetes, the cpu unit is used to define limits and requests for CPU resources. One cpu, in Kubernetes, is equivalent to 1 vCPU/Core for cloud providers and 1 hyperthread on bare-metal Intel processors.

3.2 How to understand the cpu unit in kubernetes?

  • Requests: Represents the resource limit of the container startup request, and the allocated resources must meet this requirement
  • Limits: represents the maximum number of resources that can be requested

CPU resource is computed by unit m, which means the millicore.

  • Unit m: The unit of measurement for CPU is called millicore (m). The number of CPU cores of a node is multiplied by 1000 to get the total number of CPUs of the node. For example, if a node has two cores, the total CPU of the node is 2000m.

For example, if we have a four-core CPU, then total CPU resources are 4x1000=4000m, then for the following pod:

apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
  - name: app
    image: images.my-company.example/app:v4
    resources:
      requests:
        memory: "64Mi"
        cpu: "100m"
      limits:
        memory: "128Mi"
        cpu: "500m"

This pod frontend has 100/4000=2.5% CPU resource when startup ,and it can have 500/4000=12.5% CPU resource at maximum.

And the below picture shows a pod with a 200mmax CPU resource ,e.g. 0.2 CPU core, then it can only reach 0.2 at maximum:

image-20210609163300480

4. Summary

In this post, I tried to explain the details of CPU resources limit in Kubernetes.

-->