When setting resources on Kubernetes pods, I’m finding it very difficult to achieve good memory efficiency.
I’m using the “no CPU limits, set memory=limits” philosophy that I hear heavily recommended on the internet.
The problem is, that many pods will have random memory spikes. In order for them not to be OOM Killed, you have to set the memory requests for them above their highest spike, which means most of the time they’re only using like 25% or so of their memory allocation.
I’ve been trying to optimize this one cluster, and on average I’m only getting 33% of the total memory requested for all the pods in the cluster actually being used. Whenever I try decreasing some pod’s memory requests, I eventually get OOMs. I was hoping I could reach closer to 50%, considering that this particular cluster has a stable workload.
I’m sure that I could optimize it a bit better, but not by much.
Is this a shared experience in Kubernetes? That you ultimately have to sacrifice a lot of memory efficiency.


Others are correct, the problem is the software. You are right to use memory requests and limits. The limits being the max it will use, but hopefully other pods won’t be using all of their limits at once.
So all of the pods’ memory requests on a given node will sum to < 100% of the total available memory. So you can of course say your pod requests the highest amount of ram it will ever need, but that does mean it’s reserved for that pod and won’t be used anywhere else even during downtime
K8s will allow over provisioning of ram for the limits though because it assumes it will not always need that as you are seeing.
What you can do is to set a priority class on the pod so when it spikes and you don’t have enough ram, it will kill some other pod instead of yours, but that makes other pods more volatile of course.
There’s many options at your disposal, you’ll have to decide what works best for your use case.