Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Pod resources.limits and resources.requests in Kubernetes?

Tags:

kubernetes

doc

I've been reading the kubernetes documentation https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#resource-requests-and-limits-of-pod-and-container

But it's still not clear for me what's the difference between spec.containers[].resources.limits.cpu and spec.containers[].resources.requests.cpu and what's the impact on the resource limitation

Can you please suggest some reads or books where this is explained in common english?

Thanks in advance

like image 985
Hernan Garcia Avatar asked Mar 07 '19 15:03

Hernan Garcia


2 Answers

When Kubernetes pod is scheduled on a particular node it is required the pod to have enough resources to run. Kubernetes knows resources of it's node but how does kubernetes knows the how much resources will pod takes beforehand to schedule it effectively in nodes. For that requests will be used. When we specify a request of resource kubernetes will guarantee that pod will get that amount of resource.

On other hand limit limits the resource usage by a pod. Kubernetes will not allow a pod to take more resources than the limit. When it comes to CPU if you request more kubernetes will throttle pods CPU artificially. If pod exceed a limit pod will be it will be terminated. To make it simple it simple limit is always bigger than request.

This example will give you idea about request and limit. Think that there is a pod where you have specify its memory request as 7GB and memory limit as 10GB. There are three nodes in your cluster where node1 has 2GB of memory, node2 has 8GB memory and node3 has 16GB. Your pod will never be scheduled on node1. But it will either be sceduled on node2 or node3 depending on pod current memory usage. But if it is scheduled on node3 it will be terminated in any scenario it will exceed the memory usage of 10GB.

like image 180
Hansika Weerasena Avatar answered Sep 29 '22 00:09

Hansika Weerasena


in short: for cpu & memory requests: k8s guarantee what you declared you will get when scheduler schedule your pods.

for cpu & memory limits: k8s guarantee you can not exceed the value you set.

the results when your pod exceed the limits:

  • for cpu: k8s throttling your container
  • for memory: OOM, k8s kill your pod
like image 32
Z.Liu Avatar answered Sep 29 '22 00:09

Z.Liu