Course contentsShow
← Cloud and Infrastructure
Lesson 1338 of 2,98927. Kubernetes Scheduling and ResourcesFree lesson

LimitRange Objects

Use LimitRange to enforce default requests, limits, and constraints on pods and containers in namespaces.

LimitRange Objects

You'll learn how to use LimitRange to automatically apply resource constraints and defaults across all pods in a namespace.

The Problem LimitRange Solves

Imagine a shared Kubernetes cluster where developers forget to set resource requests and limits on their pods. Some pods consume massive CPU or memory, starving others. Or worse, someone deploys a container that requests more memory than any node can provide, and it never schedules.

LimitRange acts like a safety net and helper combined—it enforces minimum/maximum resource boundaries and automatically fills in missing values when pods don't specify requests or limits.

How LimitRange Works

A LimitRange is a namespace-scoped object that defines rules for:

  • Default requests/limits – Applied when pods don't specify them
  • Min/max constraints – Reject pods that ask for too much or too little
  • Ratios – Enforce relationships (e.g., limit can't exceed 2× the request)

Unlike ResourceQuotas (which control total namespace consumption), LimitRange operates on individual pods and containers.

Common LimitRange Rules

apiVersion: v1
kind: LimitRange
metadata:
  name: resource-limits
spec:
  limits:
  - type: Container
    default:           # Default limits if not specified
      cpu: 500m
      memory: 512Mi
    defaultRequest:    # Default requests if not specified
      cpu: 200m
      memory: 256Mi
    max:               # Maximum allowed
      memory: 1Gi
    min:               # Minimum required
      memory: 128Mi

When you create a pod without specifying resources, Kubernetes applies these defaults automatically. If you try to exceed the max, the pod is rejected at admission time.

Key Takeaway:
LimitRange enforces default resource values and min/max constraints per container/pod in a namespace, preventing resource misconfiguration and ensuring baseline standards.