<p>I have a web App, that I am trying to deploy with <code>Kubernetes</code>. It's working correctly, but when I try to add <strong>resource limits</strong>, the <code>ElasticSearch</code> will not deploy.</p>
<h3>elasticsearch-deployment.yaml:</h3>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-service
spec:
  type: NodePort
  selector:
    app: elasticsearch
  ports:
  - port: 9200
    targetPort: 9200
    name: serving
  - port: 9300
    targetPort: 9300
    name: node-to-node
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: elasticsearch-deployment
  labels:
    app: elasticsearch
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      containers:
      - name: elasticsearch
        image: elasticsearch:7.9.0
        ports:
        - containerPort: 9200
        - containerPort: 9300
        env:
        - name: discovery.type
          value: single-node
        # resources:
        #   limits:
        #     memory: 8Gi
        #     cpu: &quot;4&quot;
        #   requests:
        #     memory: 4Gi
        #     cpu: &quot;2&quot;
</code></pre>
<p>If I uncomment the resources section of the file, the pod is stuck in pending:</p>
<pre><code>&gt; kubectl get pods
NAME                                        READY   STATUS    RESTARTS       AGE
backend-deployment-bd4f98697-rxsz8          1/1     Running   1 (6m9s ago)   6m40s
elasticsearch-deployment-644475545b-t75pp   0/1     Pending   0              6m40s
frontend-deployment-8bc989f89-4g6v7         1/1     Running   0              6m40s
mysql-0                                     1/1     Running   0              6m40s
</code></pre>
<p>If I check the events:</p>
<pre><code>&gt; kubectl get events
...
Warning   FailedScheduling  pod/elasticsearch-deployment-54d9cdd879-k69js  0/1 nodes are available: 1 Insufficient cpu.
Warning   FailedScheduling  pod/elasticsearch-deployment-54d9cdd879-rjj24  0/1 nodes are available: 1 Insufficient cpu.
...
</code></pre>
<p>The events says that the pod has <strong>Insufficient cpu</strong>, but I tried to change the resource limits to :</p>
<pre><code>resources:
  limits:
    memory: 8Gi
    cpu: &quot;18&quot;
  requests:
    memory: 4Gi
    cpu: &quot;18&quot;
</code></pre>
<p>Still doesn't works, the only way for it to works is to remove the resource limit, but why?</p>

Hamza Ince
<p>It is because of the request, not the limit. It means your node doesn't have enough memory to schedule a pod that requests 2 CPUs. You need to set the value to a lower one (e.g. 500m).</p>
<p>You can check your server's allocatable CPUs. The sum of all Pod's CPU requests should be lower than this.</p>
<pre class="lang-sh prettyprint-override"><code># kubectl describe nodes
...
Allocatable:
  cpu:                28
...
</code></pre>
