AutoScaling work loads without running out of memory

Viewed 178

I have a number of pods running and horizontal pod auto scaler assigned to target them, the cluster I am using can also add nodes and remove nodes automatically based on current load.

BUT we recently had the cluster go offline with OOM errors and this caused a disruption in service.

Is there a way to monitor the load on each node and if usage reaches say 80% of the memory on a node, Kubernetes should not schedule more pods on that node but wait for another node to come online.

2 Answers

The pending pods are what one should monitor and define Resource requests which affect scheduling.

The Scheduler uses Resource requests Information when scheduling the pod to a node. Each node has a certain amount of CPU and memory it can allocate to pods. When scheduling a pod, the Scheduler will only consider nodes with enough unallocated resources to meet the pod’s resource requirements. If the amount of unallocated CPU or memory is less than what the pod requests, Kubernetes will not schedule the pod to that node, because the node can’t provide the minimum amount required by the pod. The new Pods will remain in Pending state until new nodes come into the cluster.

Example:

apiVersion: v1
kind: Pod
metadata:
name: requests-pod
spec:
 containers:
 - image: busybox
   command: ["dd", "if=/dev/zero", "of=/dev/null"]
   name: main
   resources:
     requests:
       cpu: 200m
       memory: 10Mi

When you don’t specify a request for CPU, you’re saying you don’t care how much CPU time the process running in your container is allotted. In the worst case, it may not get any CPU time at all (this happens when a heavy demand by other processes exists on the CPU). Although this may be fine for low-priority batch jobs, which aren’t time-critical, it obviously isn’t appropriate for containers handling user requests.

Short answer: add resources requests but don't add limits. Otherwise, you will face the throttling issue.

Related