Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 333 of 8025. Advanced Kubernetes ConfigurationFree lesson

Enforcing Storage Quotas with Resource Quotas

Apply cluster-level resource quotas to limit the total amount of storage capacity consumed by specific namespaces, preventing runaway storage allocation costs.

In this lesson, you will learn how to prevent runaway infrastructure costs by enforcing strict storage limits on specific Kubernetes namespaces using Resource Quotas.

As you have learned, dynamic provisioning via StorageClasses makes it incredibly easy for developers to request PersistentVolumeClaims (PVCs). However, without boundaries, a team could accidentally (or intentionally) provision terabytes of expensive cloud block storage, leading to massive, unexpected monthly bills. To prevent this, Kubernetes allows us to set hard limits on the total storage capacity a namespace can consume.

Defining Storage Quotas

A ResourceQuota object tracks the total requested storage across all PVCs within a single namespace. When you create this object, the Kubernetes API server intercepts any new storage requests. If a new PVC would push the total storage volume beyond your defined limit, the API server will reject the request with a "forbidden" error.

Here is how you define a quota that limits a namespace to a maximum of 50 Gigabytes of total storage:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: storage-limit
  namespace: development-team
spec:
  hard:
    requests.storage: 50Gi

Why This Matters

By applying this to your development-team namespace, you ensure that even if a developer requests a large volume, the cluster will prevent the allocation if it exceeds the 50Gi threshold. This acts as a circuit breaker for your infrastructure budget.

When applying this, keep in mind:

  1. Scope: Quotas are namespace-scoped, meaning you can grant different limits to different teams (e.g., production gets 500Gi, sandbox gets 10Gi).
  2. Persistence: The limit applies to the sum of all PVCs in the namespace. If the total requested storage exceeds the hard limit, no further volumes can be provisioned until existing ones are deleted or the quota is increased.
  3. Control: This is an essential administrative tool for maintaining cluster hygiene and ensuring that storage resources are distributed fairly across the organization.

Key Takeaway: Use ResourceQuotas to define a hard cap on cumulative storage requests, effectively placing a budgetary guardrail on your dynamic persistent volume provisioning.