<p>I have read about k8s resource management but things are still not very clear to me.  Lets say we have 2 k8s nodes each with 22 mb memory.
Lets say Pod A has request 10mb and limit 15mb(but lets say actual usage is 5mb). so this pod is scheduled on node 1. So node1 has 22 mb memory, 5 is used by Pod A but another 17mb is available if more memory is needed by Pod A.
Pod B has request 10 and limit 15(basically the same with Pod A). so this pod is scheduled on node 2</p>
<p>So both nodes have 5 mbs of usages out of 22mb. If Pod C has a request 5mb and limit 10mb, will this pod be scheduled on any of the nodes? If yes, what would happen Pod C needs 10m memory and the other pod needs 15mb of memory?</p>
<p>What would happen if Pod C has a request of 13mb and a limit of 15mb? In this case 13(request of pod C) + 10(request of pod A) will be 23(more than 22)?</p>
<p>Does k8s try to make sure that requests of all pods &lt; available memory &amp;&amp;  limits of all pods &lt; available memory ?</p>

<p>Answering question from the post:</p>
<blockquote>
<p>Lets say Pod A has request 10mb and limit 15mb(but lets say actual usage is 5mb). so this pod is scheduled on node 1. So node1 has 22 mb memory, 5 is used by Pod A but another 17mb is available if more memory is needed by Pod A. Pod B has request 10 and limit 15(basically the same with Pod A). so this pod is scheduled on node 2</p>
</blockquote>
<p>This is not really a question but I think this part needs some perspective on how <code>Pods</code> are scheduled onto the nodes. The component that is responsible for telling Kubernetes where a <code>Pod</code> should be scheduled is: <code>kube-scheduler</code>. It <strong>could</strong> come to the situation as you say that:</p>
<ul>
<li><code>Pod A, req:10M, limit: 15M</code> -&gt; <code>Node 1, mem: 22MB</code></li>
<li><code>Pod B req:10M, limit: 15M</code> -&gt; <code>Node 2, mem: 22MB</code></li>
</ul>
<p>Citing the official documentation:</p>
<blockquote>
<h3>Node selection in kube-scheduler</h3>
<p><code>kube-scheduler</code> selects a node for the pod in a 2-step operation:</p>
<ul>
<li>Filtering</li>
<li>Scoring</li>
</ul>
<p>The filtering step finds the set of Nodes where it's feasible to schedule the Pod. For example, the PodFitsResources filter checks whether a candidate Node has enough available resource to meet a Pod's specific resource requests. After this step, the node list contains any suitable Nodes; often, there will be more than one. If the list is empty, that Pod isn't (yet) schedulable.</p>
<p>In the scoring step, the scheduler ranks the remaining nodes to choose the most suitable Pod placement. The scheduler assigns a score to each Node that survived filtering, basing this score on the active scoring rules.</p>
<p><strong>Finally, kube-scheduler assigns the Pod to the Node with the highest ranking.</strong> If there is more than one node with equal scores, kube-scheduler selects one of these at random.</p>
<p>-- <em><a href="https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/#kube-scheduler-implementation" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Scheduling eviction: Kube sheduler: Implementation</a></em></p>
</blockquote>
<hr />
<blockquote>
<p>So both nodes have 5 mbs of usages out of 22mb. If Pod C has a request 5mb and limit 10mb, will this pod be scheduled on any of the nodes? If yes, what would happen Pod C needs 10m memory and the other pod needs 15mb of memory?</p>
</blockquote>
<p>In this particular example I would much more focus on the <strong>request</strong> part rather than the actual usage. Assuming that there is no other factor that will deny the scheduling, <code>Pod C</code> should be spawned on one of the nodes (that the <code>kube-scheduler</code> chooses). Why is that?:</p>
<ul>
<li><code>resource.limits</code> will <strong>not deny</strong> the scheduling of the <code>Pod</code> (limit can be higher than memory)</li>
<li><code>resource.requests</code> will <strong>deny</strong> the scheduling of the <code>Pod</code> (request cannot be higher than memory)</li>
</ul>
<p>I encourage you to check following articles to get more reference:</p>
<ul>
<li><em><a href="https://sysdig.com/blog/kubernetes-limits-requests/" rel="nofollow noreferrer">Sysdig.com: Blog: Kubernetes limits requests</a></em></li>
<li><em><a href="https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-resource-requests-and-limits" rel="nofollow noreferrer">Cloud.google.com: Blog: Products: Containers Kubernetes: Kubernetes best practices: </a></em> (this is <code>GKE</code> blog but it should give the baseline idea, see the part on: &quot;The lifecycle of a Kubernetes Pod&quot; section)</li>
</ul>
<hr />
<blockquote>
<p>What would happen if Pod C has a request of 13mb and a limit of 15mb? In this case 13(request of pod C) + 10(request of pod A) will be 23(more than 22)?</p>
</blockquote>
<p>In that example the <code>Pod</code> <strong>will not</strong> be scheduled as the sum of requests &gt; memory (assuming no <code>Pod</code> priority). The <code>Pod</code> will be in <code>Pending</code> state.</p>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/#what-s-next" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Scheduling eviction: Kube sheduler: What's next</a></em></li>
<li><em><a href="https://www.youtube.com/watch?v=eDkE4WNWKUc" rel="nofollow noreferrer">Youtube.com: Deep Dive Into the Latest Kubernetes Scheduler Features
</a></em> - from <a href="https://www.cncf.io/" rel="nofollow noreferrer">CNCF [Cloud Native Computing Foundation]</a> conference</li>
</ul>
