ERROR

Kubernetes ResourceQuota: Fix Pod Scheduling Failure Blocking CI/CD Pipeline Deployments

Quick Fix Summary

TL;DR

Check and increase ResourceQuota limits for the affected namespace.

A Pod cannot be scheduled because the namespace's ResourceQuota has exhausted its CPU or memory allocation, preventing new workloads from starting.

Diagnosis & Causes

  • ResourceQuota limits for CPU or memory are fully utilized in the namespace.
  • A misconfigured or overly restrictive ResourceQuota object.
  • Recovery Steps

    1

    Step 1: Verify the Pod Scheduling Error

    Confirm the Pod is failing due to ResourceQuota by checking its events.

    bash
    kubectl describe pod <pod-name> -n <namespace> | grep -A 10 Events
    kubectl get events -n <namespace> --field-selector involvedObject.name=<pod-name> --sort-by='.lastTimestamp'
    2

    Step 2: Check Active ResourceQuotas in the Namespace

    List all ResourceQuotas and their current usage to identify the constrained resource.

    bash
    kubectl get resourcequotas -n <namespace> -o wide
    kubectl describe resourcequota -n <namespace>
    3

    Step 3: Analyze Total Resource Usage in the Namespace

    Sum the resource requests of all running pods to understand quota consumption.

    bash
    kubectl get pods -n <namespace> -o jsonpath='{range .items[*]}{.spec.containers[*].resources.requests.cpu}{"\n"}{end}' | awk '{s+=$1} END {print "Total CPU Requests:", s}'
    kubectl get pods -n <namespace> -o jsonpath='{range .items[*]}{.spec.containers[*].resources.requests.memory}{"\n"}{end}' | awk '{s+=$1} END {print "Total Memory Requests:", s}'
    4

    Step 4: Identify and Clean Up Unnecessary Pods (Immediate Relief)

    Delete failed, completed, or non-essential pods to free up quota.

    bash
    kubectl get pods -n <namespace> --field-selector=status.phase!=Running
    kubectl delete pod <pod-name> -n <namespace>
    5

    Step 5: Update the ResourceQuota Limits

    Increase the hard limits of the constraining ResourceQuota.

    bash
    kubectl edit resourcequota <quota-name> -n <namespace>
    # In the editor, increase values for 'limits.cpu', 'requests.cpu', etc.
    6

    Step 6: Scale Down Existing Deployments (Alternative)

    Temporarily reduce replica counts of non-critical deployments to free quota for the new pod.

    bash
    kubectl scale deployment <deployment-name> -n <namespace> --replicas=<lower-number>
    7

    Step 7: Verify Pod Schedules Successfully

    After making changes, monitor the pod's status to confirm it transitions to Running.

    bash
    kubectl get pod <pod-name> -n <namespace> -w
    kubectl logs <pod-name> -n <namespace> --tail=50
    8

    Step 8: Implement Preventive Monitoring

    Set up alerts for ResourceQuota usage to prevent future pipeline blocks.

    yaml
    # Example: Create a Prometheus alert rule for high quota usage.
    # - alert: NamespaceQuotaHighUsage
    #   expr: kube_resourcequota_created * on(namespace) group_left kube_resourcequota{type="used"} / kube_resourcequota{type="hard"} > 0.8
    #   for: 5m

    Architect's Pro Tip

    "This often happens when CI/CD pipelines deploy to a shared development namespace. A single team or a runaway job can consume the entire quota, blocking all other deployments. Consider implementing per-team or per-pipeline namespaces with dedicated quotas."

    Frequently Asked Questions

    Can I bypass a ResourceQuota by deploying to a different namespace?

    Yes, ResourceQuotas are namespace-scoped. Deploying to a namespace without a quota or with higher limits is a valid workaround, but it bypasses the intended resource governance.

    Why does my pod fail even though `kubectl top nodes` shows plenty of resources?

    ResourceQuotas enforce limits at the namespace level, independent of actual node capacity. A namespace can be 'full' even if the cluster has free resources.

    What's the difference between `requests` and `limits` in a ResourceQuota?

    A quota for `requests.cpu` governs the sum of all pod resource requests (guaranteed minimum). A quota for `limits.cpu` governs the sum of all pod resource limits (maximum allowed). A pod must satisfy both to be scheduled.

    Related Kubernetes Guides