In the Linux system, the two core concepts for containers are Namespace and Cgroups. We can use Cgroups technology to limit resources. These resources can be divided into many types, such as CPU, memory, storage, network, and so on. Among them, computing resources are the most basic type of resource, and all containers require this type of resource.
So, in this article, let’s discuss how to limit the CPU usage of a container.
Taking the Kubernetes platform as an example, let’s look at the spec definition in the pod/container below. There are two items in the CPU resource-related definition, Request CPU and Limit CPU.
apiVersion: v1
kind: Pod
metadata:
name: frontend
spec:
containers:
- name: app
image: images.my-company.example/app:v4
env:
resources:
requests:
memory: "64Mi"
cpu: "1"
limits:
memory: "128Mi"
cpu: "2"
…Many beginners to Kubernetes may not initially understand the purpose of these two parameters.
Here’s the conclusion: the values of “Request CPU” and “Limit CPU” in the Pod Spec will ultimately control container CPU resources through the configuration of the CPU Cgroup.
Next, I will start by discussing the CPU usage of processes, and then guide you to create several…
