How to check maximum memory I can request for a pod in a kubernetes cluster?

8/6/2021

I am using an EKS cluster with 4 nodes. There are multiple applications running in the kubernetes cluster(nearly 30-40 pods) with different cpu and memory requests.

Now I wish to increase the memory of one particular pod, now how to choose what maximum memory I can assign to the pod in my cluster.

My Idea is to get the free memory inside the kubernetes nodes and based on that will decide the maximum memory that I can assign to pod.

I am trying with free command in pods to check the memory available.

How can I get the free memory available in my EKS cluster nodes?

Note: There is no metrics server installed in my EKS cluster

-- Bala krishna
amazon-eks
kubernetes
kubernetes-pod
memory
nodes

1 Answer

8/6/2021

There may be namespace specific limits, which could be lower than whats available at the node level. In this case, you will have to consider the namespace limits.

However, if thats not the case, as a starting value, you may the below command and look at the "Requests" column and choose the request value in your pod that is lower than the available amount shown for your most utilized node.

kubectl get node --no-headers | while read node status; do echo '>>>>  ['$node']'; kubectl describe node $node | grep Resource -A 3 ;done
>>>>  [node-be-worker-1]
  Resource           Requests    Limits
  --------           --------    ------
  cpu                300m (7%)   100m (2%)
  memory             220Mi (2%)  220Mi (2%)
>>>>  [node-be-worker-2]
  Resource           Requests    Limits
  --------           --------    ------
  cpu                200m (5%)   100m (2%)
  memory             150Mi (1%)  50Mi (0%)
>>>>  [node-be-worker-3]
  Resource           Requests    Limits
  --------           --------    ------
  cpu                400m (10%)  2100m (52%)
  memory             420Mi (5%)  420Mi (5%)
>>>>  [node-master-0]
  Resource           Requests    Limits
  --------           --------    ------
  cpu                650m (32%)  100m (5%)
  memory             50Mi (1%)   50Mi (1%)

Explanation: The command lists all the nodes and loops over to describe the nodes and then filters the lines for "Resource" and prints the string and the next 3 lines.

You should be able to tweak the above command to work for namespace too.

-- Rakesh Gupta
Source: StackOverflow