<p>I have two containers withing my pod (<code>PodA</code>)</p>
<p>The first container (<code>C1</code>) has the following limits</p>
<pre><code>Limits:                                                                                                                                                                                                
  cpu:     2                                                                                                                                                                                           
  memory:  1Gi                                                                                                                                                                                         Requests:                                                                                        
  cpu:     100m                                                                                  
  memory:  128Mi
</code></pre>
<p>The second container (<code>C2</code>) has no requests/limits specified</p>
<p>I have the following questions</p>
<ol>
<li>From what I can see with a <code>kubectl describe nodes</code>, the memory/cpu request/limits for the <code>PodA</code> are the same as the one from <code>C1</code>. Is that correct?</li>
<li>What are the memory/cpu limits for <code>C2</code>? Is it unbounded? Limited to the limits of <code>PodA</code> (e.g. limits of <code>C1</code>)?</li>
<li>Follow up of #2 -&gt; What happens if <code>C2</code> asks for more than 1Gi of memory? Will the container run out of memory, and cause the whole pod to crash? Or will it be able to grab more memory, as long as the node has free memory?</li>
</ol>
<p>I tried to google, but all the examples I saw where some where resource limits are set for both of the containers</p>

<p>Kubernetes places your pods in <a href="https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/" rel="noreferrer">Quality Of Service</a> classes based on whether you have added requests and limits.</p>
<p>If all your containers in the pods have limits set, the pod falls under <code>Guaranteed</code> class.</p>
<p>If at least on container in the pod has requests(or limits) set, the pod comes under <code>Burstable</code> class.</p>
<p>If there are no requests or limits set for all container, the pods comes under <code>Best Effort</code> class.</p>
<p>In your example, your pod falls under <code>Burstable</code> class because <code>C2</code> does not have limits set.</p>
<hr />
<p>These requests and limits are used in two contexts - scheduling and resource exhaustion.</p>
<h3>Scheduling</h3>
<p>During scheduling, requests are considered to select node based on available resources. <code>limits</code> can be over-comitted and are not considered for scheduling`decisions.</p>
<h3>Resource exhaustion</h3>
<p>There are two resources on which you can specify the requests and limits natively  - cpu and memory</p>
<p>CPU is a compressible resource i.e., kernel can throttle cpu usage of a process if required by allocating less CPU time. So a process is allowed to use as much CPU as it wants if other processes are idle. If another process needs the cpu, OS can just throttle the cpu time for the process using more CPU. The unused cpu time will be split in the ratio of their requests. If you don't want this behaviour of unlimited cpu usage i.e., you want your container to not cross certain threshold, you can set the limit.</p>
<p>Memory is not a compressible resource. Once allocated to a process, kernel cannot regain the memory. So if a limit is set, a process gets OOM killed if it tries to use more than the limit. If no limit is set, process can allocate as much as it wants but if there is a memory exhaustion, the only way to regain some free memory is to kill a process. This is where the QoS class come into picture. A <code>BestEffort</code> class container would be the first in line to get OOM killed. Next <code>Burstable</code> class containers would be killed before any <code>Guaranteed</code> class container gets killed. In situations where the containers are of same QoS class, the container using higher percentage of memory compared to its request would be OOM killed.</p>
<hr />
<blockquote>
<p>From what I can see with a kubectl describe nodes, the memory/cpu request/limits for the PodA are the same as the one from C1. Is that correct?</p>
</blockquote>
<p>Yes</p>
<blockquote>
<p>What are the memory/cpu limits for C2? Is it unbounded? Limited to the limits of PodA (e.g. limits of C1)?</p>
</blockquote>
<p>CPU as a compressible resource is unbounded for all containers(or upto the limit if the limit is specified). C2 would get throttled when the other containers with requests set needs more cpu time.</p>
<blockquote>
<p>Follow up of #2 -&gt; What happens if C2 asks for more than 1Gi of memory? Will the container run out of memory, and cause the whole pod to crash? Or will it be able to grab more memory, as long as the node has free memory?</p>
</blockquote>
<p>It can grab as much memory it wants. But it would be the first to get OOM killed if the nodes has no more free memory to allocate to other processes.</p>
