How container resource limits works in Kubernetes

Viewed 61

In the official documentation here, the pod.spec.container.resources.limits is defined as follows : "Limits describes the maximum amount of compute resources allowed."

I understand that k8s prohibits a pod from consuming more resources than specified in limits. The documentation does not say that a pod is not scheduled in a node that does not have the amount of resources specified in limits.

For instance, if each node in my cluster has 2 cpus, and I try to deploy a pod defining a cpu limit to 3, my pod will never be running and will be in status Pending.

Here is the example template : mypod.yml

apiVersion: v1
kind: Pod
metadata:
  name: secondbug
spec:
  containers:
  - name: container
    image: nginx
    resources:
      limits:
        cpu: 3

Is this behaviour intended and why?

1 Answers

You have 3 kinds of pods, pods with no request definition, pods that are burstable which have limits and requests and the third kind which has only limits or requests defined.

For the third case if you only define limits or requests, the other one will be defined by the first one meaning:

resources:
  limits:
    cpu: 3

Is actually:

resources:
  limits:
    cpu: 3
  requests:
    cpu: 3

So you cant really define only one without the other. So in your case, you want to define requests for it so it won't be defined by the limits.

Related