<p>I don't understand how replication works in Kubernetes.</p>
<p>I understand that two replicas on different nodes will provide fault tolerance for the application, but I don’t understand this:</p>
<p>Suppose the application is given the following resources:</p>
<pre><code>---
apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
  - name: app
    image: images.my-company.example/app:v4
    resources:
      requests:
        memory: &quot;1G&quot;
        cpu: &quot;1&quot;
      limits:
        memory: &quot;1G&quot;
        cpu: &quot;1&quot;
</code></pre>
<p>The application has two replicas. Thus, in total, 2 CPUs and 2G RAM are available for applications.</p>
<p>But what happens if the application receives a request with a size of 1.75G? After all, only 1G RAM is available in one replica. Will the request be distributed among all replicas?</p>
<p><strong>Answer for Harsh Manvar</strong></p>
<p>Maybe you misunderstood me?</p>
<p>What you explained is not entirely true.</p>
<p>Here is a real, working deployment of four replicas:</p>
<pre><code>$ kubectl get deployment dev-phd-graphql-server-01-master-deployment
NAME                                          READY   UP-TO-DATE   AVAILABLE   AGE
dev-phd-graphql-server-01-master-deployment   4/4     4            4           6d15h
</code></pre>
<pre><code>$ kubectl describe deployment dev-phd-graphql-server-01-master-deployment
 ...
    Limits:
      cpu:     2
      memory:  4G
    Requests:
      cpu:     2
      memory:  4G
 ...
</code></pre>

<p>No, it won't get distributed one replica will start simply and the other will stay in <strong>pending</strong> state.</p>
<p>If you will describe that pending POD(replica) it show this error :</p>
<pre><code>0/1 nodes available: insufficient cpu, insufficient memory
</code></pre>
<blockquote>
<p>kubectl describe pod <strong>POD-name</strong></p>
</blockquote>
<p>K8s will check for the requested resource</p>
<pre><code>requests:
        memory: &quot;1G&quot;
        cpu: &quot;1&quot;
</code></pre>
<p>if mentioned minimum requested resources available it will deploy the replica and other will goes in pending state.</p>
<p><strong>Update</strong></p>
<blockquote>
<p>But what happens if the application receives a request with a size of
1.75G? After all, only 1G RAM is available in one replica.</p>
</blockquote>
<pre><code>requests:
        memory: &quot;1G&quot;
        cpu: &quot;1&quot;
      limits:
        memory: &quot;1G&quot;
        cpu: &quot;1&quot;
</code></pre>
<p>If you have a set request of <strong>1 GB</strong> and application start using the <strong>1.75 GB</strong> it will kill or restart the POD due to hitting the limit.</p>
<p>But yes in some cases container might can exceeds the limit if Node has memory available.</p>
<blockquote>
<p>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. If a terminated Container can be restarted, the kubelet
restarts it, as with any other type of runtime failure.</p>
</blockquote>
<p>Read more at : <a href="https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/#exceed-a-container-s-memory-limit" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/#exceed-a-container-s-memory-limit</a></p>
<p>You might would like to read this also : <a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#how-pods-with-resource-limits-are-run" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#how-pods-with-resource-limits-are-run</a></p>
