Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are hardware resources defined in Kubernetes? CPU and RAM

What is a simple explanation to resource allocation and definitions in kubernetes? What does it mean to allocate "1000m" CPU units and 1024Mi off memory?

like image 920
Amir Mehler Avatar asked May 16 '18 11:05

Amir Mehler


People also ask

What is CPU and memory in Kubernetes?

Each node in a Kubernetes cluster is allocated memory (RAM) and compute power (CPU) that can be used to run containers. A Kubernetes cluster defines a logical grouping of one or more containers into pods. You can then deploy and manage pods on top of your nodes.

What does 0.5 CPU mean in Kubernetes?

According to the docs, CPU requests (and limits) are always fractions of available CPU cores on the node that the pod is scheduled on (with a resources. requests. cpu of "1" meaning reserving one CPU core exclusively for one pod). Fractions are allowed, so a CPU request of "0.5" will reserve half a CPU for one pod.

How much RAM does Kubernetes use?

Kubernetes uses memory requests to determine on which node to schedule the pod. For example, on a node with 8 GB free RAM, Kubernetes will schedule 10 pods with 800 MB for memory requests, five pods with 1600 MB for requests, or one pod with 8 GB for request, etc.


1 Answers

(tried to write it in simpler language than the official docs)

CPU

In Kubernetes each CPU core is allocated in units of one "milicore" meaning one Virtual Core (on a virtual machine) can be divided into 1000 shares of 1 milicore. Allocating 1000 milicores will give a pod one full CPU. Giving more will require the code in the pod to able to utilize more than one core.

Memory

Very simple. Each Megabyte you allocate is reserved for the pod.

Requests

Minimal resources that are guaranteed to be given to the pod. If there are not enough resources to start a pod on any node it will remain in "Pending" state.

Limits

CPU Limit Will cause the the pod to throttle down when hitting the limit.

Memory Limit When a pod utilizes all of it's memory and asks for more than the limit it will considered a memory leak and the pod will get restarted.

Target (defined in the Horizontal Pod Autoscaler)

Can be applied to CPU, Memory and other custom metrics (more complicated to define.

It's might be a good idea to set resources for a pod in sizes of A B and C where: A < B < C. With requests = A, Target = B and Limits = C. Just remember that a fully loaded node might prevent pods from reaching their "target" and not never scale up.

like image 94
Amir Mehler Avatar answered Oct 23 '22 15:10

Amir Mehler