Skip to content

Instantly share code, notes, and snippets.

@DanielYWoo
Last active August 31, 2022 07:07
Show Gist options
  • Save DanielYWoo/6c9693fc6bbe3641111a0089cecc4399 to your computer and use it in GitHub Desktop.
Save DanielYWoo/6c9693fc6bbe3641111a0089cecc4399 to your computer and use it in GitHub Desktop.
k8s memory quota - request and limit
Memory
- Limit:
○ On a ns: used to calculate available resource: avail = limit - used
○ Sum(pod limit) must be less than the ns limit quota
○ Special behavior: On a pod without ns: kill it if exceed
- Request:
○ On a ns: used to control how much can be requested
○ Sum(pod request) must be less than the ns request quota
○ Special behavior: When ns request exists, pod request missing, pod request falls back to pod limit
Memory
In any case, Pod request respect total available memory (total_physical - total_used)
- When no request, no limit on ns
○ When pod has no request, only limit:
§ No quota
○ When pod has no limit, only request:
§ No quota
○ When pod has both request and limit
§ No quota
§ OOM killer can kick in if exceeds
○ When pod has nothing
§ No quota
- When only limit on ns
○ When pod has no request, only limit
§ Pod limit must <= quota: limit_ns - sum(pod_limit)
§ E.g., ns limit 100, pod limit is 60, end up with 1 pod
○ When pod has no limit, only request
§ Error, need a pod limit
○ When pod has both request and limit
§ Pod limit must <= quota: limit_ns - sum(pod_limit)
§ Pod request is not used for quota
○ When Pod has nothing
§ Error, need a pod limit
- When only request on ns
○ When pod has no request, only limit
§ pod request must <= quota: Request_ns - sum(pod_limit)
§ Pod limit act as pod request
§ E.g., ns request = 100, pod limit = 60, end up with 1 pod
○ When pod has no limit, only request
§ Pod request must <= quota: request_ns - sum(pod_request)
§ Pod limit is not used for quota
§ E.g., ns request= 100, pod request=40, we end up with 2 pods
○ When pod has both request and limit
Pod request must <= quota: request_ns - sum(pod_request)
Pod limit is not used for quota
E.g., ns request = 100, pod request= 40, pod limit = 70, we end up with 2 pods.
- When both request and limit on ns
○ When pod has no request, only limit
You expect: Pod limit must <= quota: limit_ns - sum(pod_limit)
Actually, because ns_request exists, pod request missing, pod request falls back to pod limit, and request quota is smaller than limit quota, so you will see: Pod request must <= quota: request_ns - sum(pod_limit)
E.g., ns request = 100, ns limit = 200, pod limit = 60, consider pod limit, you expect 3 pods, but actually, we see 1 pod, because pod request falls back to 60, we reach request quota first.
○ When pod has no limit, only request
§ Report error
○ When pod has both request and limit
§ Both could work
§ E.g.,
NS: Request 100, limit 200
Pod: request 30, limit 100, 2
Pod: request 60, limit 100, 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment