0
votes

If I have a node with 16 GB RAM and pods that have a memory request of 1GB and memory limit of 4GB, how many of these pods will be scheduled on the node? 4 or 16?

I would think it is 16 based on this https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/

The scheduler ensures that, for each resource type, the sum of the resource requests of the scheduled Containers is less than the capacity of the node.

And what if a pod starts using 4GB memory which is within its limits, will it be evicted? rescheduled?

I have a use case where my pods will typically use X memory but sometimes use 4X memory. How should I set my requests and limits for this case? Should I set the request to X or 4X?

2

2 Answers

1
votes

Kubernetes scheduler should be able to schedule 16 pods each with 1GB memory requests to a node with free capacity of 16GB memory .If at any point in time any pod starts to use more memory(within limits) it will be allowed to do so. But the moment total memory consumption goes beyond the capacity of node then pods which are consuming above their requests will be randomly terminated and rescheduled unless there is a priority in which case lower priority pods will be be the victim.

1
votes

Requests: This value is used for scheduling. It’s the minimum amount of resources a container needs to run. Be careful, the request does not mean these are always dedicated resources for the container.

Limits: This is the maximum amount of this resource that the node will allow the containers to use.

https://sysdig.com/blog/kubernetes-pod-evicted/

First, kubelet tries to free node resources, especially disk, by deleting dead pods and its containers, and then unused images. If this isn’t enough, kubelet starts to evict end-user pods in the following order:

  • Best Effort.
  • Burstable pods using more resources than its request of the starved resource.
  • Burstable pods using less resources than its request of the starved resource.

enter image description here

If a Container exceeds its memory limit, it might be terminated. If it is restartable, the kubelet will restart it, as with any other type of runtime failure.

If a Container exceeds its memory request, it is likely that its Pod will be evicted whenever the node runs out of memory.

https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/

A Container can exceed its memory request if the Node has memory available.

But a Container is not allowed to use more than its memory limit. If a Container allocates more memory than its limit, the Container becomes a candidate for termination. If the Container continues to consume memory beyond its limit, the Container is terminated

https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/