Description
Kubernetes uses the memory request to decide where a Pod fits. The container can use more memory than it requests.
If you specify only a memory limit, Kubernetes copies it to the request unless admission has supplied a different default.
Potential impact
A low request can crowd a node and increase memory pressure and out-of-memory risk. A high request can leave capacity unused or prevent the Pod from being scheduled.
Remediation
- Set
resources.requests.memoryfrom measured usage and review it alongside the limit. Adjust it as the workload changes. - Inspect the created Pod to see any defaults from LimitRange, then test the effective values under load.
Examples
Provide the stress image’s arguments and any required CPU request. Choose memory values for your workload.
Before
yaml
apiVersion: v1
kind: Pod
metadata:
name: memory-demo
spec:
containers:
- name: memory-demo-ctr-1
image: polinux/stress
resources:
limits:
memory: "200Mi"
requests:
cpu: "0.5"
After
yaml
apiVersion: v1
kind: Pod
metadata:
name: memory-demo
spec:
containers:
- name: memory-demo-ctr
image: polinux/stress
resources:
limits:
memory: "200Mi"
requests:
memory: "100Mi"
Explanation:
- Before: With a
200Milimit and no other default, the effective request is200Mi. - After: The scheduler uses the explicit
100Mirequest. The container keeps its200Milimit.