Setting Memory Requests
What you'll learn: How to guarantee minimum memory allocation for your containers using memory requests in Kubernetes pod specifications.
Why Memory Requests Matter
Just as you learned to set CPU requests to reserve processing power, memory requests tell Kubernetes the minimum amount of RAM your container needs to function properly. This ensures the scheduler places your pod only on nodes with enough available memory.
Think of it like reserving a table at a restaurant: you tell them how many people are coming (memory request), and they guarantee you'll have enough seats. Without a reservation, you might show up and find no space available.
How Memory Requests Work
When you define a memory request:
- The Kubernetes scheduler checks all nodes for available memory
- It only schedules your pod on nodes with at least that much memory free
- That memory is "reserved" for your container, even if it doesn't use it all immediately
- Other pods can't claim that reserved memory
Setting Memory Requests in Your Pod Spec
You specify memory requests in the resources section of your container definition:
apiVersion: v1
kind: Pod
metadata:
name: memory-demo
spec:
containers:
- name: app
image: nginx
resources:
requests:
memory: "256Mi"
This pod requests 256 mebibytes (MiB) of memory. Kubernetes will only schedule it on nodes with at least 256 MiB available.
Common Memory Request Values
"128Mi"- Lightweight services"256Mi"- Standard web applications"1Gi"- Memory-intensive applications"4Gi"- Databases or caching layers
Key Takeaway: Memory requests guarantee your container gets scheduled on a node with sufficient RAM, preventing out-of-memory failures due to poor placement. Always set realistic memory requests based on your application's actual needs.