Hello and welcome to this lecture.
My name is Mumshad
Mannambath. Let us look at a 3 Node Kubernetes cluster. Each node has a set of CPU, Memory and Disk
resources available.
Every POD consumes a set of resources.
In this case 2 CPUs , one Memory and some disk space. Whenever a POD is placed on a Node, it consumes resources
available to that node. As we have discussed before, it is the kubernetes scheduler that decides which
Node a POD goes to. The scheduler takes into consideration, the amount of resources required by a POD
and those available on the Nodes. In this case, the scheduler schedules a new POD on Node 2. If the node
has no sufficient resources, the scheduler avoids placing the POD on that node Instead places the POD
on one where sufficient resources are available if there is no sufficient resources available on any
of the nodes, Kubernetes holds back scheduling the POD, and you will see the POD in a pending state.
If you look at the events, you will see the reason – insufficient cpu. Let us now focus on the resource
resource requirements for each POD. What are these blocks and what are their values?
By default, kubernetes assumes that a POD or a container within a POD requires .5 CPU &
256 Mebibyte of memory.
This is known as the resource request for a container the minimum amount of CPU or memory requested
by the container when the scheduler tries to place the pod on a node.
It uses these numbers to identify a node which has sufficient amount of resources available.
Now if you know that your application will need more than these you can modify these values by specifying
them in your pod or deployment definition files in the simple pod definition file.
add a section called resources, under which add requests and specify the new values for memory and cpu usage.
In this case I set it to 1GB of memory and 1 count of vCPU.
So what does 1 count of CPU really mean?
Remember these blocks are used for illustration purposes only.
It doesn't have to be in the increment of point five.
You can specify any value as low as 0.1. 0.1
CPU can also be expressed as 100m were m stands for milli.
You can go as low as 1m, but not lower than that. 1 count of CPU is equivalent to 1 vCPU.
That’s 1 vCPU in AWS, or 1 Core in GCP or Azure or 1 Hyperthread. You could request a higher number
of CPUs for the container, provided your Nodes are sufficiently funded. Similarly, with memory you could
specify 256 Mebibyte using the Mi suffix. Or specify the same value in Memory like this. Or use the
suffix G for a gigabyte.
Note the difference between G and Gi. G is Gigabyte and it refers to a 1000 Megabytes, whereas Gi
Gi refers to Gibibyte and refers to 1024 Mebibyte.
The same applies to megabyte and kilobytes.
Let's now look at a container running on a node in the docker world a docker container has no limit
to the resources it can consume on a Node. Say a container starts with 1 vCPU on a Node, it can go up
and consume as much resource as it requires, suffocating the native processes on the node or other containers
of resources.
However you can set a limit for the resource usage on these pods by default.
Kubernetes sets a limit of 1vCPU to containers. So if you do not specify explicitly, a container will be limited
to consume only 1 vCPU from the Node.
The same goes with memory. By default, kubernetes sets a limit of 512 Mebibyte on containers.
if you don't like the default limit you can change them by adding a limit section under the resources
section in your pod definition file. Specify new limits for memory and cpu you like this when the
pod is created, kubernetes sets new limits for the container.
Remember that the limits and requests are set for each container within the pod.
So what happens when a pod tries to exceed resources beyond its specified limit.
In case of the CPU, kubernetes throttles the CPU so that it does not go beyond the specified limit.
A container cannot use more CPU resources than its limit.
However, this is not the case with memory. A container CAN use more memory resources that its limit.
So if a pod tries to consume more memory than its limit constantly, the POD will be terminated.
Well that's it for this lecture on resource requirements in kubernetes.
Head over to the coding exercises section and practice viewing configuring and troubleshooting
resource requirements in kubernetes.
Thank you and I will see you in the next lecture.