What happens if a Kubernetes pod exceeds its cpu resources 'limit'?

8/22/2019
NAME                      CPU(cores)   MEMORY(bytes)   
apache-757ddfbc75-khhfw   10m          61Mi
-- Shashank Omre
kubernetes

3 Answers

8/22/2019

Starting from scratch

When you create a Pod, the Kubernetes scheduler selects a node for the Pod to run on. Each node has a maximum capacity for each of the resource types: the amount of CPU and memory it can provide for Pods. The scheduler ensures that, for each resource type, the sum of the resource requests of the scheduled Containers is less than the capacity of the node. Note that although actual memory or CPU resource usage on nodes is very low, the scheduler still refuses to place a Pod on a node if the capacity check fails. This protects against a resource shortage on a node when resource usage later increases, for example, during a daily peak in request rate.

To specify a CPU request for a container, include the resources:requests field in the Container resource manifest. To specify a CPU limit, include resources:limits.

CPU requests and limits are associated with Containers, but it is useful to think of a Pod as having a CPU request and limit. The CPU request for a Pod is the sum of the CPU requests for all the Containers in the Pod. Likewise, the CPU limit for a Pod is the sum of the CPU limits for all the Containers in the Pod.

Pod scheduling is based on requests. A Pod is scheduled to run on a Node only if the Node has enough CPU resources available to satisfy the Pod CPU request.

In below pod's configuration file the container requests 100 CPU, which is likely to exceed the capacity of any Node in your cluster.

apiVersion: v1
kind: Pod
metadata:
  name: cpu-demo
  namespace: cpu-test
spec:
  containers:
  - name: cpu-demo-ctr-2
    image: vish/stress
    resources:
      limits:
        cpu: "100"
      requests:
        cpu: "100"
    args:
    - -cpus
    - "2"

After creating pod you will get similar output:

enter image description here

It shows that the container cannot be scheduled because of insufficient CPU resources on the Nodes.

Overall documentations: kubernetes-resources, managing-resources.

-- MaggieO
Source: StackOverflow

8/22/2019

Docs: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#how-pods-with-resource-limits-are-run

"A Container might or might not be allowed to exceed its CPU limit for extended periods of time. However, it will not be killed for excessive CPU usage."

Container will not be allowed to use more CPU than it's limit on average, other container will be protected from excessive CPU usage.

-- Keilo
Source: StackOverflow

8/26/2019

k8s doc refer:

A Container might or might not be allowed to exceed its CPU limit for extended periods of time. However, it will not be killed for excessive CPU usage.

Most of those case, nothing will happen. CPU usage is very very flexible.

-- Ray
Source: StackOverflow