Understanding the resources and limits of Kubernetes

Rohit
2 min readOct 11, 2023

--

Today we’ll learn how resources and limits work with pods in Kubernetes

Quick overview of resources and limits
we give pods resources so that whenever they get scheduled on k8s nodes they get the specified amount of resources and we put a limit on the pods so that they won’t consume the resources above the limit.

Kubernetes scheduler checks the limit of pods and allocates the pods to node on the basis of the memory resources available to the node and schedules it.

For simplicity purposes, we have 2 pods and we’ll create various scenarios to understand how it works.

Case1 No request and limit defined

In this case, what happens is pods will consume as many resources as they want as no limit and request is defined. and it can happen that 1 pod consume all the memory and CPU and the other pod starve for memory and CPU.

Case2 Request is defined but the limit is not set

Let’s suppose we have a defined request of 2 CPUs and 2 GB memory for the pod. Kubernetes will make sure that each pod gets at least 2GB memory and 2 CPUs as we have not set the limit so pods can consume as much memory and CPU as they want.

Case3 Request is not set Limit is defined

In this case, Kubernetes automatically sets the request as a limit and pods won’t be able to get more than the limit.

Case4 Request and limit both are defined

In this case, Kubernetes will make sure that each pod get the requested amount of resources and does not exceed the limit which we have defined.

Important to consider

If any pod tries to consume more than the limit it’s specified then it gets the OOM killed error.

But with the CPU if any pod tries to use more than the limit then Kubernetes throttles the CPU to be within the limit it has specified.

--

--