0

Assume that Kubernetes has scheduled two pods A and B in a node N. If the resource capacity of the Node N is (30 CPU, 70 Memory) and pod A requests (5 CPU, 8 memory) and pod B requestes (4 CPU, 10 memory), is it possible to share the resources among two pods in a way that we maintain the efficieny of the cluster and maximize the allocation of pods? How can I change the codes to achieve this? Assuming that each pod maintains 1 container.

HamiBU
  • 127
  • 1
  • 10
  • 1
    What do you mean by "share the resources among two pods"? You can share a single node N if that's what you are asking; you will just need to configure the scheduler policy to configure Affinity/Anti-Affinity for close packing of your pods. – Frank Yucheng Gu Mar 28 '19 at 14:45

1 Answers1

1

Kubernetes already does that.

Resource Requests are soft reservations, that means, the scheduler will consider it as a requirement when placing the pod in the node, it will allocate the resource to a POD but won't reserve the resources to be used exclusively by the pod that requested it.

If the POD request 1Gb of memory and consumed only 500Mb, other pods will be able to consume the remainder.

The main issue is when other PODs does not set limits, this will prevent the scheduler of controlling the load properly and other running pods might affect the pod. Other issue is when Limits are set too high and when being consumed will reach the node capacity.

To have a proper balance and efficiency, requests and limits should be set appropriately and prevent over-commitment.

This other SO shows a nice example of it: Allocate or Limit resource for pods in Kubernetes?

Diego Mendes
  • 10,631
  • 2
  • 32
  • 36
  • Thanks for your response. If we assume that pod have not set resource limits, how can I indicate that the whole resources in the cluster will be divides fairly among those two pods. Actually, I would like to allocate all the resources only to those two pods. – HamiBU Mar 28 '19 at 15:05
  • If you don't set limits, some pods will consume more resources than others,without limits there is no guarantee that the resources will be split fairly. You can add policies to restrict pod creation without limits. In case you need more resources to the pods, instead of letting the pod consume too much resource. you setup auto scale to add more replicas of it (if the application can split the processing). Other option instead of adding replicas, you deploy more pods with lower priority, when higher priority pods need more resources, other with lower priority get evicted from nodes. – Diego Mendes Apr 01 '19 at 10:13