Limiting cpu for a set of pods

3/27/2021

I have a java based application consisting of several pods (lets say 4) which is licensed by the sum of millicores (lets say we have purchased 2000mC of licenses). The application is running on a cluster host with 4000mC to support the memory required for the application. The application is bursty so each pod will want to use 2000mC at some point in time, but not at the same time. If the cpu limit is set to 2000mC per pod then over 4 pods our license liability would be 8000mC although in reality the host capacity would limit it to 4000mC. This is still double the licenses we have paid for. If we limit each pod to 500mC to ensure we never exceed 2000mC and stay within our license limit, the pods are under-resourced.

Is there a way to limit the CPU for a group of pods to allow any single pod to burst to the maximum limit while collectively not allowing them to exceed the maximum?

-- D.Baillie
cpu-usage
kubernetes
scheduling

2 Answers

3/28/2021

My suggestion would be to enable pod auto scaling. There are 2 types of it:

  1. Horizontal Pod Autoscaler (HPA) - If your pods are identical and you do not require all 4 at once, then implement HPA for Pods. With this you can keep a minimum number of pods you require and then scale them to the maximum number you want based on metrics like CPU, Memory utilisation etc. HPA
  1. Vertical Pod Autoscaling (VPA) - You can implement VPA by utilizing the resource management provided by kubernetes. You can add parameter resources.requests.cpu to start your pod with and in case the utilisation increases you can limit it using parameter resources.limits.cpu. Resource management

Combination of both above methods will be ideal in your case.

-- Gautam Rajotya
Source: StackOverflow

3/27/2021

A good strategy here would be to play with both requests and limit parameter of resources.

As an example for your case, you can use following configuration

  • resources.requests.cpu - 750mC
  • resources.limits.cpu - 2000mC

This will allocate 3000m (740 x 4) CPU in the node, allowing additional 1000mC for CPU to burst.

Reference - https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/#motivation-for-cpu-requests-and-limits

-- vishalsaugat
Source: StackOverflow