Resource allocation in Kubernetes

Hitesh Pattanayak
2 min readMar 25, 2022

Scheduler which is a component in master node decides which node the pod goes to. While doing so, the scheduler takes into consideration the amount of resources by a pod and availability of it in node.

If there is no sufficient resources available on any of the nodes, Kubernetes keeps the pod in pending state with event reason as insufficient CPU/memory/disk.

Default allocation of CPU is 0.5, of MEM is 256 Mi as part of (Resource request)

An example of how resource allocation can be configured by a Pod (check spec/containers/resources section)

apiVersion: v1
kind: Pod
metadata:
name: example-pod
labels:
name: example-pod
spec:
containers:
- name: example-pod
image: polinux/stress
resources:
requests:
memory: "5Mi"

CPU 0.1 means 100m, where ‘m’ stands for ‘milli’.

CPU can be requested as low as 1m.

1 CPU is equivalent to:

  • 1 AWS vCPU
  • 1 GCP core
  • 1 Azure core
  • 1 Hyperthread

1Gi memory means 1 Gibibyte while 1G means 1 Gigabyte.

We can also set limits under spec/containers/resources, to prevent pod from consuming too much resources and suffocating other pods. Making changes to the above example.

apiVersion: v1
kind: Pod
metadata:
name: example-pod
labels:
name: example-pod
spec:
containers:
- name: example-pod
image: polinux/stress
resources:
requests:
memory: "5Mi"
limits:
memory: "20Mi"

When pod tries to go beyond the limit CPU, k8 tries to throttle the cpu so that pod will not be able to consume more CPU.

When pod tries to go beyond the limit memory, k8 terminates the pod.

The status OOMKilled indicates that it is failing because the pod ran out of memory. Identify the memory limit set on the POD.

--

--

Hitesh Pattanayak

Senior Product Engineer @ Infracloud Technologies | 7 years of experience | Polyglot | Backend Developer | Kubernetes and AWS practitioner | Finance Enthusiast