Resources & Limits

Using Resources & Limits we can define the minimum and maximum amount of resources a container within a Pod can will use during it’s life cycle, this can be defines by the limits of CPU and Memory usage.

When we define limits for a Pod, the Kube Scheduler ensures that the resources requested are granted, else the pod is stopped from being scheduled on a Worker Node and set to a pending state

Default Behavior

By default every pod that is scheduled on Kubernetes has access to the complete compute and memory available on the Worker Node, unless any limits are set on the containers within them, a container that leaks memory can easily consume all the memory and a recursive function can starve other applications from CPU time

It is recommended that we define the set amount of resources to be requested, this allows in ensuring that a minimum amount of resources are available for a container at any given time

CPU

When a pod requests for CPU it can range from 1m / 0.0.1CPU to 1 CPU with 0.01m being the lowest, here the CPU is equivalent to 1 vCPU on all cloud providers or 1 hyperthread on a regular CPU

Memory

Memory can also be requested in the same manner, using Gi (GibbiByte), G (Gigabyte) and Mi (MebbiByte) and M (Megabyte)

If a container uses more resources than the specified limits, the container is throttled for sometime, if the container keeps using these resources for a prolonged period of time, the Pod is terminated from the node and scheduled accordingly

Global Behavior

If we do not define any limits or requests for any container, they use all the available resources which is really concerning using Limit Range in the Namespaces