For SREs, ensuring critical application uptime during Kubernetes cluster maintenance is paramount. Pod Disruption Budgets (PDBs) are your primary tool for guaranteeing a minimum number of healthy application instances remain available during voluntary disruptions like node drains, cluster upgrades, or autoscaling events. Instead of merely hoping your application can tolerate a node being taken offline, a PDB explicitly defines a minAvailable (e.g., 70% or 3 replicas) or maxUnavailable (e.g., 1 replica) threshold for a set of pods. The Kubernetes scheduler and cluster autoscaler respect PDBs, preventing operations that would violate these availability guarantees, thus safeguarding your application's reliability during planned changes.
Managing multi-tenant or shared Kubernetes clusters demands robust resource governance. Resource Quotas provide this by allowing SREs to set limits on the total compute resources (CPU, memory), storage resources, and even the count of Kubernetes objects (e.g., pods, services, persistentvolumeclaims) within a specific namespace. This prevents a single team or application from monopolizing cluster resources, ensuring fair sharing and mitigating the "noisy neighbor" problem. By configuring quotas, you can enforce budget constraints, prevent resource exhaustion, and maintain overall cluster stability, which are crucial for consistent performance and predictable operational costs.
While Resource Quotas manage the aggregate resource consumption in a namespace, Limit Ranges operate at the pod and container level. An SRE can use Limit Ranges to enforce default resource requests and limits for pods if they aren't explicitly specified, preventing poorly configured applications from running without any resource boundaries. Furthermore, Limit Ranges can define the minimum and maximum CPU/memory requests and limits allowed for any pod or container within that namespace. This creates guardrails, ensuring that even if users specify resources, they fall within acceptable operational parameters, complementing Resource Quotas by ensuring individual components adhere to sensible resource profiles.
Key Takeaways
- PDBs: Essential for maintaining application availability during planned cluster maintenance and upgrades.
- Resource Quotas: Enforce namespace-level resource governance, preventing resource exhaustion and "noisy neighbors."
- Limit Ranges: Define pod/container-level resource defaults and constraints, complementing quotas for granular control.
- Together, these ensure cluster stability, fairness, and predictable application behavior in shared environments.
Code Example
apiVersion: v1
kind: ResourceQuota
metadata:
name: team-a-dev-quota
namespace: team-a-dev
spec:
hard:
pods: "10"
requests.cpu: "2"
requests.memory: "4Gi"
limits.cpu: "4"
limits.memory: "8Gi"
persistentvolumeclaims: "5"
requests.storage: "50Gi"How this code works
This Kubernetes YAML defines a ResourceQuota named team-a-dev-quota for the team-a-dev namespace. Its primary purpose is to enforce limits on the total resources that pods and other Kubernetes objects can consume within this specific namespace. This mechanism ensures fair resource distribution and prevents any single team or application from monopolizing cluster resources, which is crucial for maintaining stability and predictability in a shared SRE environment.
The spec.hard section specifies the strict upper bounds for various resources. For instance, pods: "10" dictates that no more than 10 pods can be running simultaneously in the team-a-dev namespace. requests.cpu: "2" and requests.memory: "4Gi" set the cumulative maximum for all pod resource requests—these are the guaranteed minimums for CPU and memory that Kubernetes aims to provide. Similarly, limits.cpu: "4" and limits.memory: "8Gi" define the cumulative maximum for all pod resource limits—the absolute ceiling for CPU and memory usage. A subtle but important aspect is that for a pod to be admitted into the namespace, it must satisfy both the total requests.* and the total limits.* quotas simultaneously. Finally, persistentvolumeclaims: "5" and requests.storage: "50Gi" cap the number and total storage requested by persistent volume claims, managing disk space consumption.