# How to allocate resources for EKS Fargate Pods # Overview Refer to this documentation https://docs.aws.amazon.com/eks/latest/userguide/fargate-pod-configuration.html , we have some restrictions and tricky points to allocate the suitable resources for Pods **AWS Fargate** comes with a **resource spec** table which indicates us how they provide the fixed resources for Kubernetes Pods, the resources we specify for Pods will be ceiled to the nearest spec !https://prod-files-secure.s3.us-west-2.amazonaws.com/6ecddc07-3e11-44f3-a26a-8b7cc8ab8ad7/f159e046-e1a8-402d-89d2-48d707a15890/image-20240216-094335.png Some important points to note: - **AWS Fargate** adds **256** MB to each Pod's memory reservation for the required Kubernetes components (`kubelet`, `kube-proxy`, and `containerd`) - The maximum request out of any Init containers is used to determine the Init request vCPU and memory requirements. - Requests for all long-running containers are added up to determine the long-running request vCPU and memory requirements. # Guide Knowing the above things, we would have these two formula to calculate the resources for EKS Fargate Pods ## Memory Calculated in **GB** unit ```java max(sumContainersRAM, sumInitContainersRAM) + 0.25 (fargate) + 0.25 (DD) + gapRAM = ceiling RAM ``` In this formula, the *gapRAM* is the gap memory that we would use to add on the container memory so that all of them could sum up the nearest ceiling memory For example: we have a Kotlin application that requires **2GB** of memory to run, we would do it 2 ways: - We could try to run the Kotlin container with **1.5GB** memory, in this case, the total memory is sum up to **2GB** (with DD and fargate) that would suit the resource spec from Fargate with **no** gap memory - We could increase the resource spec, the nearest one is **3GB,** then we could allocate the Kotlin container with **2.5GB** (with **0.5GB** gap memory) ## CPU Calculated in **vCPU** unit ```java max(sumContainersCPU, sumInitContainersCPU) + 0.05 (DD) + gapCPU = ceiling CPU ``` In this formula, the *gapCPU* is the gap CPU that we would use to add on the container CPU so that all of them could sum up the nearest ceiling CPU For example: we have a Kotlin application that requires **1vCPU** of memory to run, we would do it 2 ways: - We could try to run the Kotlin container with **0.95vCPU**, in this case, the total CPU is sum up to **1vCPU** (with DD) that would suit the resource spec from Fargate with **no** gap CPU - We could increase the resource spec, the nearest one is **2vCPU,** then we could allocate the Kotlin container with **1.95vCPU** (with **0.9** gap vCPU)