Node.js › Docker & Deployment
What is the purpose of setting explicit CPU and memory resource requests and limits for a Node.js container in Kubernetes?
IntermediateAnswer
A resource request tells Kubernetes the minimum CPU/memory a container needs, used for scheduling decisions (placing the pod only on a node with enough available capacity); a limit caps the maximum a container can consume, with Kubernetes throttling CPU usage above the limit or killing (OOMKilling) the container if it exceeds its memory limit -- setting these appropriately prevents one misbehaving pod from starving others on the same node, and prevents a memory leak from silently degrading the entire node.
resources:
requests:
memory: '256Mi'
cpu: '250m'
limits:
memory: '512Mi'
cpu: '500m'Real-world example A team without resource limits on their Node.js pods experienced a memory leak in one service gradually consuming all available memory on a shared node, starving unrelated pods; adding a memory limit ensures that specific pod gets OOMKilled and restarted long before it can impact its neighbors.