Requests & Limits
Every node has a limited amount of resources, and we need to utilize and manage those resources within control; otherwise, the node failover is just one step ahead. So the K8s resource manifest file should specify how much a pod can use of those resources.
This is controlled by adding a resources section in the containers field with two properties named "requests" and "limits."
resources:
requests:
memory: 128Mi
cpu: 500m
limits:
memory: 512Mi
cpu: 100mThis part of YAML should be a child of the container field, as this is going to use it.
Now requests define how much resources the pod is going to start with, and limits define the maximum amount of resources the pod can use from the node. Now there can be 3 scenarios:
If a pod asks for and utilizes the resources within its boundary, it will be working as desired.
If a pod utilizes more than its limits, it will stop and throw an Out Of Memory (OOM) error, and the node will be safe from crashing.
If a pod asks for more than the resource available in the node, it will be stuck in a pending state.
Quick Note
Here Mi is for mebibytes, which is the binary measurement of resources instead of decimal megabytes.
And the "m" in CPU is the millicore. Where 1 core is divided into 1000 millicores.