Your pod creation fails with "LimitRange exceeded" or similar error. LimitRanges set minimum and maximum resource constraints per pod or container in a namespace. When your pod's resource requests or limits don't match LimitRange constraints, Kubernetes rejects the pod creation.

Understanding LimitRange

LimitRanges enforce resource constraints at the namespace level. They set min/max for CPU, memory, and storage per pod or container. They also set default requests/limits for pods that don't specify resources.

When a pod violates LimitRange, the admission controller rejects it. This can happen for various reasons: requests below minimum, limits above maximum, limits without requests, or defaults being applied unexpectedly.

Diagnosis Commands

Check LimitRange configuration:

```bash # List LimitRanges in namespace kubectl get limitrange -n namespace kubectl get limits -n namespace # Short name

# Describe LimitRange kubectl describe limitrange limitrange-name -n namespace

# Get detailed configuration kubectl get limitrange limitrange-name -n namespace -o yaml ```

Check pod error:

```bash # Check pod creation error kubectl describe pod pod-name -n namespace | grep -A 10 "Error|LimitRange"

# Check events for LimitRange errors kubectl get events -n namespace --field-selector reason=FailedCreate

# Look for specific error message kubectl get events -n namespace | grep -i "limitrange|exceeded|minimum|maximum" ```

Check pod resource specification:

```bash # Check pod resource requests/limits kubectl get pod pod-name -n namespace -o yaml | grep -A 20 resources

# Or for deployment kubectl get deployment deployment-name -n namespace -o yaml | grep -A 20 resources ```

Common Solutions

Solution 1: Fix Requests Below Minimum

LimitRange may specify minimum CPU/memory:

bash
# Check LimitRange minimum
kubectl get limitrange limitrange-name -n namespace -o yaml | grep -A 10 "min"

Fix resource requests:

```yaml # LimitRange minimum: # cpu: 100m # memory: 128Mi

# Pod requests too low: containers: - name: app resources: requests: cpu: "50m" # Below minimum 100m memory: "64Mi" # Below minimum 128Mi

# Fix: Increase requests to meet minimum containers: - name: app resources: requests: cpu: "100m" # Minimum memory: "128Mi" # Minimum ```

Solution 2: Fix Limits Above Maximum

LimitRange may specify maximum CPU/memory:

bash
# Check LimitRange maximum
kubectl get limitrange limitrange-name -n namespace -o yaml | grep -A 10 "max"

Fix resource limits:

```yaml # LimitRange maximum: # cpu: 2 # memory: 2Gi

# Pod limits too high: containers: - name: app resources: limits: cpu: "4" # Above maximum 2 memory: "4Gi" # Above maximum 2Gi

# Fix: Reduce limits containers: - name: app resources: limits: cpu: "2" # Maximum memory: "2Gi" # Maximum ```

Solution 3: Handle Default Limits Applied

LimitRange can apply default limits to pods without limits:

bash
# Check default limits in LimitRange
kubectl get limitrange limitrange-name -n namespace -o yaml | grep -A 10 "default"

Pods without explicit limits get defaults:

```yaml # LimitRange default: # cpu: 500m # memory: 512Mi

# Pod without limits: containers: - name: app resources: requests: cpu: "100m" memory: "128Mi" # No limits specified - defaults applied

# After defaults applied: # limits: cpu=500m, memory=512Mi # If requests exceed defaults, error occurs ```

Fix by explicitly setting limits:

yaml
containers:
  - name: app
    resources:
      requests:
        cpu: "100m"
        memory: "128Mi"
      limits:
        cpu: "200m"    # Explicitly set
        memory: "256Mi"

Solution 4: Fix Limit-to-Request Ratio

Some LimitRanges enforce maxLimitRequestRatio:

bash
# Check ratio constraints
kubectl get limitrange limitrange-name -n namespace -o yaml | grep -A 5 "maxLimitRequestRatio"

Fix request-to-limit ratio:

```yaml # LimitRange maxLimitRequestRatio: # cpu: 5 (limit can be up to 5x request) # memory: 3

# Invalid ratio: containers: - name: app resources: requests: cpu: "100m" limits: cpu: "1" # Ratio is 10x, exceeds max 5

# Fix: Adjust to valid ratio containers: - name: app resources: requests: cpu: "200m" limits: cpu: "1" # Ratio is 5x, valid ```

Solution 5: Fix Default Request Applied

LimitRange can apply default requests to pods without requests:

bash
# Check default requests
kubectl get limitrange limitrange-name -n namespace -o yaml | grep -A 10 "defaultRequest"

Explicitly set requests:

```yaml # Pod without requests: containers: - name: app # No resources specified # Gets default requests AND default limits

# Fix: Set explicit requests containers: - name: app resources: requests: cpu: "100m" memory: "128Mi" limits: cpu: "200m" memory: "256Mi" ```

Solution 6: Adjust LimitRange Configuration

If your application needs higher limits, adjust LimitRange:

yaml
apiVersion: v1
kind: LimitRange
metadata:
  name: namespace-limits
  namespace: namespace
spec:
  limits:
  - type: Container
    max:
      cpu: "4"      # Increase from 2
      memory: "4Gi"  # Increase from 2Gi
    min:
      cpu: "50m"
      memory: "64Mi"
    default:
      cpu: "500m"
      memory: "512Mi"
    defaultRequest:
      cpu: "100m"
      memory: "128Mi"
    maxLimitRequestRatio:
      cpu: "10"
      memory: "5"

Apply updated LimitRange:

bash
kubectl apply -f limitrange.yaml

Solution 7: Check Type-Specific Limits

LimitRange can apply to different types:

yaml
spec:
  limits:
  - type: Container  # Per-container limits
  - type: Pod        # Total pod limits
  - type: PersistentVolumeClaim  # Storage limits

Check all limit types:

bash
# Check all limit types
kubectl get limitrange limitrange-name -n namespace -o yaml | grep -B 2 -A 10 "type:"

Fix pod-level limits:

```yaml # Pod-level LimitRange: # type: Pod # max: # cpu: "4" # memory: "4Gi"

# Container limits must not exceed pod limits when summed # For 3 containers, each can use up to 1.33Gi memory ```

Solution 8: Check PVC Limits

LimitRange can limit PVC storage:

yaml
spec:
  limits:
  - type: PersistentVolumeClaim
    max:
      storage: "10Gi"
    min:
      storage: "1Gi"

Fix PVC request:

```yaml # PVC requesting too much: apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pvc spec: resources: requests: storage: "50Gi" # Above max 10Gi

# Fix: Reduce storage request spec: resources: requests: storage: "10Gi" # Maximum ```

Solution 9: Delete LimitRange (If Appropriate)

Remove LimitRange if it's blocking necessary workloads:

```bash # Save LimitRange config kubectl get limitrange limitrange-name -n namespace -o yaml > limitrange-backup.yaml

# Delete LimitRange kubectl delete limitrange limitrange-name -n namespace

# Recreate if needed kubectl apply -f limitrange-backup.yaml ```

Solution 10: Check ResourceQuota Interaction

ResourceQuota adds namespace-level constraints:

```bash # Check ResourceQuota kubectl get resourcequota -n namespace

# ResourceQuota and LimitRange work together # ResourceQuota: namespace total limits # LimitRange: per-pod/container limits ```

Verification

After fixing LimitRange issues:

```bash # Check pod is created successfully kubectl get pods -n namespace

# Verify resources applied kubectl get pod pod-name -n namespace -o jsonpath='{.spec.containers[*].resources}'

# Check no LimitRange errors kubectl get events -n namespace | grep -i limitrange ```

LimitRange Validation Script

```bash # Check if pod spec meets LimitRange #!/bin/bash NAMESPACE="my-namespace" LIMIT_RANGE=$(kubectl get limitrange -n $NAMESPACE -o yaml)

echo "=== LimitRange Constraints ===" echo "$LIMIT_RANGE" | grep -A 20 "limits:"

echo "" echo "=== Pod Resource Spec ===" kubectl get pod pod-name -n $NAMESPACE -o yaml | grep -A 10 "resources:" ```

LimitRange Exceeded Causes Summary

CauseError MessageSolution
Request below min"minimum resource request"Increase requests
Limit above max"maximum resource limit"Reduce limits
Defaults applied unexpectedlyPod has unexpected limitsSet explicit limits
Ratio violation"ratio exceeds maxLimitRequestRatio"Adjust request/limit ratio
Pod limit exceededContainer sums exceed pod maxReduce container limits
PVC storage too large"storage exceeds maximum"Reduce PVC request

Prevention Best Practices

Check namespace LimitRanges before deploying pods. Set explicit resource requests and limits in all deployments. Ensure requests don't exceed limits. Calculate request-to-limit ratios. Consider pod-level limits when multiple containers. Validate PVC storage requests. Monitor LimitRange violations in events.

LimitRange exceeded errors are straightforward once you see the actual constraints. The kubectl describe limitrange command shows you exactly what min/max/default values apply, and you just need to ensure your pod spec matches those constraints.