Skip to content

Kubernetes: maximum memory usage per Container is 4Gi, but limit is 16Gi

AItested on kind v0.33, kubectl 1.37

In a multi-tenant platform every namespace sets limits. A LimitRange defines default and maximum values per container. A pod that wants more never arrives – the API rejects it on creation.

Symptom

kubectl -n tenant-acme run fat --image=curlimages/curl:8.22.0 --restart=Never \
  --overrides='{"spec":{"containers":[{"name":"fat",
  "image":"curlimages/curl:8.22.0","resources":{"limits":{"memory":"16Gi"}}}]}}'
Error from server (Forbidden): pods "fat" is forbidden: maximum memory usage
  per Container is 4Gi, but limit is 16Gi

In the course the second of three counter-checks tests the LimitRange's maximum in the namespace tenant-acme.

Diagnosis

A pod without its own values shows which defaults the LimitRange fills in.

kubectl -n tenant-acme get pod plain -o jsonpath='{.spec.containers[0].resources}'
{"limits":{"cpu":"500m","memory":"512Mi"},"requests":{"cpu":"100m","memory":"128Mi"}}

Causes

maximum memory usageThe LimitRange's maximum is exceeded

The LimitRange allows at most 4Gi per container. A limit of 16Gi violates that and admission rejects the pod immediately.

DefaultsThe same LimitRange sets defaults

Pods without values get requests and limits filled in. That prevents a quota on requests.cpu from rejecting pods without requests.

Fix

Lower the pod's limit to at most 4Gi. If the tenant really needs more, adjust the LimitRange on purpose – keeping the namespace's quota in mind.
kubectl -n tenant-acme delete pod plain --now

Don't: Delete the LimitRange in the tenant namespace so a single pod gets through – then no pod has limits any more.

▶
Break it yourself and find it – free
Running LLM platforms hands-on, Day 6: multi-tenant Kubernetes – quotas, LimitRanges, NetworkPolicies, Pod Security and RBAC.
Go to day 6 →

FAQ

What is the difference between a LimitRange and a ResourceQuota?

The LimitRange limits single containers and sets defaults, the ResourceQuota limits the sum of all pods in the namespace.

Does this apply to GPUs too?

For GPUs the quota only knows requests.nvidia.com/gpu; in the pod, request and limit must be equal.

Related error patterns

More