Differences between memory and CPU limits
Using LimitRange
Differences between memory and CPU limits
There is a difference in what happens to a container when it reaches its limit for CPU and memory usage. CPU is a compressible resource, which means Kubernetes can just stop giving that specific container CPU time if a container tries to use more CPU than it should. The container will not be killed. It will just not have to keep running with the amount of CPU time it has available.
With memory, it’s different. If a container tries to allocate more memory than it can, Kubernetes will kill the process. Then, depending on the restartPolicy that is defined for this pod, it can be restarted.
Using LimitRange
So we saw that defining resource requests are useful to help Kubernetes schedule our pod in a node that has enough resources and defining a limit will guarantee that a rogue container won’t affect other applications sharing the same worker node. It is a good idea to always set these properties.
Kubernetes allows us to define a LimitRange with default values that will be used for every container that we run in a namespace.