Kubernetes - How to calculate resources we need for each container?

Solution 1:

Resources to be assigned to the pod depend on your application usage. For example when installing jenkins using helm it specified following resource requests and limits:

  resources:
    requests:
      cpu: "50m"
      memory: "256Mi"
    limits:
      cpu: "2000m"
      memory: "4096Mi"

But to avoid pod termination due to insufficient resources you can use Horizontal Pod Autoscaler with resource metrics to scale pods up or down based on resource consumption (or any other custom metrics, like requests etc.). HPA requires metrics-server to be running in your cluster.

It can be easily created using kubectl autoscale, for example:

kubectl autoscale deployment <deployment-name> --cpu-percent=50 --min=1 --max=10

Where --min is minimum number of replicas to be running and --max is the maximum replicas of the pods that will be created in case of load increase.