Review Kubernetes namespace resource quotas

Manage namespace allocation separately from individual container limits.

Description

ResourceQuota limits aggregate resource requests or object counts in a namespace. A CPU or memory request quota controls what Kubernetes admits. It neither reserves node capacity nor caps a running container’s usage.

Potential impact

Unbounded requests or Pod counts can leave less room for other workloads. A quota that is too low can reject necessary creations or updates.

Remediation

  • Set quotas to fit the namespace’s workloads and available capacity. For CPU or memory request quotas, supply the required requests on Pods or set container defaults with LimitRange.
  • Test which creations and updates are admitted. Existing Pods keep running when a quota is added. Use container limits when you also need runtime caps.

Examples

Ensure the mynewpod namespace exists and choose an image and values for your workload. In this quota, cpu: "1000" means 1,000 CPUs. One CPU is 1000m.

Before

yaml
apiVersion: v1
kind: Pod
metadata:
  name: pod1
  namespace: mynewpod
spec:
  containers:
    - name: app
      image: images.my-company.example/app:v4

The Pod has no explicit requests. Check the namespace for existing quotas and review current usage.

After

yaml
apiVersion: v1
kind: ResourceQuota
metadata:
  name: pods-high
  namespace: mynewpod
spec:
  hard:
    cpu: "1000"
    memory: 200Gi
    pods: "10"
---
apiVersion: v1
kind: Pod
metadata:
  name: pod1
  namespace: mynewpod
spec:
  containers:
    - name: app
      image: images.my-company.example/app:v4
      resources:
        requests:
          cpu: "250m"
          memory: "64Mi"

The namespace allows total requests of 1,000 CPUs and 200Gi of memory, and up to 10 non-terminal Pods. This Pod requests 250m of CPU and 64Mi of memory.

References