Kahibaro
Discord Login Register

Resource quotas and limits

Why quotas and limits matter in OpenShift

In OpenShift, every project (namespace) shares a finite pool of cluster resources: CPU, memory, storage, and object counts (Pods, Services, etc.). Without controls, a single application or team can consume disproportionate resources, affecting others and potentially destabilizing the cluster.

Resource quotas and limits provide:

This chapter focuses on how OpenShift implements resource quotas and per-container limits within projects, and how they interact.

Key concepts: quota vs. limit

At a high level:

They complement each other:

ResourceQuota: controlling project-wide usage

What ResourceQuota can limit

A ResourceQuota can restrict:

The exact set depends on the cluster version and enabled APIs, but the pattern is consistent: quota keys define a maximum for some measurable resource or count.

Basic structure of a ResourceQuota

A typical ResourceQuota YAML looks like:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: project-quota
  namespace: my-project
spec:
  hard:
    requests.cpu: "4"
    limits.cpu: "8"
    requests.memory: "8Gi"
    limits.memory: "16Gi"
    pods: "40"
    persistentvolumeclaims: "10"
    requests.storage: "200Gi"

Key fields:

How quota enforcement works

When you create or modify a resource (e.g. Deployment, Pod, PVC), the API server:

  1. Calculates the effective resource requests/limits for the new or updated objects.
  2. Sums these with the usage of existing resources in the same namespace.
  3. Compares the total against the hard limits defined in ResourceQuota.

If the new total would exceed any quota:

Quotas are enforced at admission time (when objects are created/updated), not continuously by some background process.

Multiple quotas per namespace

You can define multiple ResourceQuota objects in a namespace. Their effects combine:

This allows more granular policy definition, for example:

LimitRange: per-container policies inside a project

While quotas cap the total, LimitRange controls the resources at the pod/container level within a namespace.

What LimitRange controls

A LimitRange can define:

Limit ranges apply to:

Example LimitRange

apiVersion: v1
kind: LimitRange
metadata:
  name: container-limits
  namespace: my-project
spec:
  limits:
  - type: Container
    default:
      cpu: "500m"
      memory: "512Mi"
    defaultRequest:
      cpu: "250m"
      memory: "256Mi"
    max:
      cpu: "2"
      memory: "2Gi"
    min:
      cpu: "100m"
      memory: "128Mi"

Implications:

If you try to create a pod whose container violates these constraints, the admission is denied.

Interaction between quotas and limits

Understanding the interaction is crucial for avoiding confusing errors.

Automatic requests/limits vs. quota

When a namespace has both:

then:

Example:

If you create 5 pods without explicit requests, each gets 500m:

From the developer’s perspective, it may look like they “just created pods” and hit quota unexpectedly; the defaults from LimitRange are responsible for the usage.

Common error scenarios

Typical API error messages when hitting quotas or limits:

As a user, these messages point to either a ResourceQuota or LimitRange object by name; you can inspect them to understand the constraint.

Typical patterns for setting quotas and limits

Per-environment quotas

Organizations often apply different quotas per environment:

Per-team or per-application segmentation

Quotas can be used to:

Working with quotas and limits as a developer

Even if you’re not a cluster admin, quotas and limits affect how you design and deploy your applications.

Specifying requests and limits explicitly

Defining resources is essential for predictable behavior:

resources:
  requests:
    cpu: "200m"
    memory: "256Mi"
  limits:
    cpu: "500m"
    memory: "512Mi"

Benefits:

Estimating usage against quota

To avoid surprises:

  1. Estimate per-pod usage (requests/limits).
  2. Multiply by desired replica count.
  3. Compare the totals to the project’s quota.

If your Deployment will scale up (e.g. HPA), factor in the maximum replica count when checking against the quota.

Understanding failures when scaling

Scaling a Deployment or StatefulSet may fail if:

In that case:

As a developer:

Viewing and understanding quotas and limits in OpenShift

You typically interact with quotas and limits via:

OpenShift web console

Within a project/namespace:

You can:

`oc` CLI basics

Core commands (names may vary slightly by version, but this is the common pattern):

These commands help diagnose why deployments fail and how resources are being consumed.

Best practices for using quotas and limits

From a practical, day-to-day perspective:

Used correctly, resource quotas and limits give you predictable, stable environments on OpenShift while protecting shared infrastructure from accidental overload.

Views: 13

Comments

Please login to add a comment.

Don't have an account? Register now!