#
Limit the CPU utilization
This tutorial explains how we can limit the CPU utilization by the containers in Kubernetes.
Kubernetes provides a shared pool of resources that it allocates based on how we configure our containerized applications.
By default, a pod in Kubernetes will run with no limits on CPU and memory in a default namespace. This can create problems related to contention for resources.
You can provide more information for the scheduler using two parameters that specify CPU utilization:
Request
: sets the minimum amount of CPU required for the container. Kubernetes aggregates all container requests into a single pod request. This information is used by the Scheduler to take a decision regarding where Kubernetes could deploy a pod.Limit
: sets a maximum amount of allows CPU utilization by specifying a limit on the container.
Here we have an example of Pod definition using CPU limits in my-first-pod-cpu.yml file:
my-first-pod-cpu.yml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod-cpu
labels:
zone: prod
version: v1
spec:
containers:
- name: nginx-c
image: nginx:1.14.2
ports:
- containerPort: 8080
resources:
requests:
cpu: "250m"
limits:
cpu: "500m"
Info
cpu: "250m"
: means 25% from a CPU core (physical or virtual).
In order to deploy this Pod we can run the following command:
kubectl apply -f my-first-pod-cpu.yml