<p>I am trying to add resource and limits to my deployment on Kuberenetes Engine since one of my deployment on the pod is continuously getting evicted with an error message <code>The node was low on resource: memory. Container model-run was using 1904944Ki, which exceeds its request of 0.</code> I assume that the issue could be resolved by adding resource requests. </p>

<p>When I try to add resource requests and deploy, the deployment is successful but when I go back and and view detailed information about the Pod, with the command
<code>kubectl get pod default-pod-name --output=yaml --namespace=default</code>
It still says the pod has request of cpu: 100m and without any mention of memory that I have allotted. I am guessing that the cpu request of 100m was a default one. Please let me know how I can allot the requests and limits, the code I am using to deploy is as follows:</p>

<pre><code>kubectl run model-run --image-pull-policy=Always --overrides='
{
    "apiVersion": "apps/v1beta1",
    "kind": "Deployment",
    "metadata": {
        "name": "model-run",
        "labels": {
            "app": "model-run"
        }
    },
    "spec": {
        "selector": {
            "matchLabels": {
                "app": "model-run"
            }
        },
        "template": {
            "metadata": {
                "labels": {
                    "app": "model-run"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "model-run",
                        "image": "gcr.io/some-project/news/model-run:development",
                    "imagePullPolicy": "Always",
                      "resouces": {
                        "requests": [
                          {
                            "memory": "2048Mi",
                            "cpu": "500m"
                          }
                        ],
                        "limits": [
                          {
                            "memory": "2500Mi",
                            "cpu": "750m"
                          }
                        ]
                      },
                        "volumeMounts": [
                            {
                                "name": "credentials",
                                "readOnly": true,
                                "mountPath":"/path/collection/keys"
                            }
                        ],
                        "env":[
                            {
                                "name":"GOOGLE_APPLICATION_CREDENTIALS",
                                "value":"/path/collection/keys/key.json"
                            }
                                ]
                    }
                ],
                "volumes": [
                    {
                        "name": "credentials",
                        "secret": {
                            "secretName": "credentials"
                        }
                    }
                ]
            }
        }
    }
}
'  --image=gcr.io/some-project/news/model-run:development
</code></pre>

<p>Any solution will be appreciated</p>

Ranga Vittal
<blockquote>
  <p>The node was low on resource: memory. Container model-run was using 1904944Ki, which exceeds its request of 0.</p>
</blockquote>

<p>At first the message seems like there is a lack of resource in the <code>node</code> itself but the second part makes me believe you are correct in trying to raise the request limit for the container.</p>

<p>Just keep in mind that if you still face errors after this change, you might need to add mode powerful node-pools to your cluster.</p>

<p>I went through your command, there is a few issues I'd like to highlight:</p>

<ul>
<li><code>kubectl run</code> was <a href="https://github.com/kubernetes/kubernetes/pull/68132" rel="nofollow noreferrer">deprecated</a> in 1.12 to all resources except for pods and it is retired in version 1.18.</li>
<li><code>apiVersion": "apps/v1beta1</code> is <a href="https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/" rel="nofollow noreferrer">deprecated</a>, and starting on v 1.16 it is no longer be supported, I replaced with <code>apps/v1</code>. </li>
<li>In <code>spec.template.spec.container</code> it's written <code>"resouces"</code> instead of <strong><code>"resources"</code></strong></li>
<li>after fixing the resources the next issue is that <code>requests</code> and <code>limits</code> are written in <code>array</code> format, but they need to be in a <code>list</code>, otherwise you get this error:</li>
</ul>

<pre><code>kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
error: v1beta1.Deployment.Spec: v1beta1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Resources: v1.ResourceRequirements.Limits: ReadMapCB: expect { or n, but found [, error found in #10 byte of ...|"limits":[{"cpu":"75|..., bigger context ...|Always","name":"model-run","resources":{"limits":[{"cpu":"750m","memory":"2500Mi"}],"requests":[{"cp|...
</code></pre>

<ul>
<li>Here is the fixed format of your command:</li>
</ul>

<pre><code>kubectl run model-run --image-pull-policy=Always --overrides='{
  "apiVersion": "apps/v1",
  "kind": "Deployment",
  "metadata": {
    "name": "model-run",
    "labels": {
      "app": "model-run"
    }
  },
  "spec": {
    "selector": {
      "matchLabels": {
        "app": "model-run"
      }
    },
    "template": {
      "metadata": {
        "labels": {
          "app": "model-run"
        }
      },
      "spec": {
        "containers": [
          {
            "name": "model-run",
            "image": "nginx",
            "imagePullPolicy": "Always",
            "resources": {
              "requests": {
                "memory": "2048Mi",
                "cpu": "500m"
              },
              "limits": {
                "memory": "2500Mi",
                "cpu": "750m"
              }
            },
            "volumeMounts": [
              {
                "name": "credentials",
                "readOnly": true,
                "mountPath": "/path/collection/keys"
              }
            ],
            "env": [
              {
                "name": "GOOGLE_APPLICATION_CREDENTIALS",
                "value": "/path/collection/keys/key.json"
              }
            ]
          }
        ],
        "volumes": [
          {
            "name": "credentials",
            "secret": {
              "secretName": "credentials"
            }
          }
        ]
      }
    }
  }
}'  --image=gcr.io/some-project/news/model-run:development
</code></pre>

<ul>
<li>Now after aplying it on my Kubernetes Engine Cluster <code>v1.15.11-gke.13</code> , here is the output of <code>kubectl get pod X -o yaml</code>:</li>
</ul>

<pre><code>$ kubectl get pods
NAME                         READY   STATUS    RESTARTS   AGE
model-run-7bd8d79c7d-brmrw   1/1     Running   0          17s

$ kubectl get pod model-run-7bd8d79c7d-brmrw -o yaml
apiVersion: v1
kind: Pod
metadata:
  labels:
    app: model-run
    pod-template-hash: 7bd8d79c7d
    run: model-run
  name: model-run-7bd8d79c7d-brmrw
  namespace: default
spec:
  containers:
  - env:
    - name: GOOGLE_APPLICATION_CREDENTIALS
      value: /path/collection/keys/key.json
    image: nginx
    imagePullPolicy: Always
    name: model-run
    resources:
      limits:
        cpu: 750m
        memory: 2500Mi
      requests:
        cpu: 500m
        memory: 2Gi
    volumeMounts:
    - mountPath: /path/collection/keys
      name: credentials
      readOnly: true
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-tjn5t
      readOnly: true
  nodeName: gke-cluster-115-default-pool-abca4833-4jtx
  restartPolicy: Always
  volumes:
  - name: credentials
    secret:
      defaultMode: 420
      secretName: credentials

</code></pre>

<ul>
<li>You can see that the resources limits and requests were set.</li>
</ul>

<p>If you still have any question let me know in the comments!</p>
