โšก
Zero to Platform Architect2026
Phase 3 & 3B: DevSecOps & Fleet Patching

Lesson 3: Continuous Compliance (AWS Config) & PodDisruptionBudgets (PDB) with Exception Handling

๐Ÿง  The Concept (Explain Like Iโ€™m 5)

Imagine you manage a large hospital emergency department:

  • Point-in-Time Audit (The Once-a-Year Surprise Inspection): A state health inspector visits your hospital on December 1st for 2 hours. If everything looks clean that morning, you receive a gold certificate. The next day, staff can leave hazardous chemicals on the floor, and nobody notices for 364 days. (This is traditional manual compliance).
  • Continuous Compliance (AWS Config): An automated, AI-powered camera in every hospital hallway that monitors safety 24/7. The millisecond an unencrypted chemical canister is placed in a hallway, an alarm rings, and an automated robotic cleaner moves it to a secure vault (Automated Remediation).
  • PodDisruptionBudgets / PDB (The Minimum Emergency Staffing Rule): The hospital requires at least 3 doctors on duty at all times (minAvailable: 3). If the hospital administrator wants to send doctors to an optional training workshop (Node Draining / AMI Upgrades), the administrator asks: โ€œCan Doctor Alice go to training right now?โ€ The chief of staff checks the room: If 4 doctors are working, Doctor Alice is permitted to leave. But if only 3 doctors are working, the chief of staff shouts: โ€œDENIED! We cannot drop below our emergency staffing budget!โ€

๐Ÿข The Enterprise Context (Why Platform Architects Care)

  1. The Evolution from Audits to Continuous Enforcement: Under FedRAMP, SOC 2 Type II, and ISO 27001, compliance is not a point-in-time screenshot. Regulators require cryptographic proof that security controls (e.g. EBS volume encryption, restricted security groups, S3 public access block) were enforced continuously 100% of the time.
  2. The Conflict Between Cluster Operations & Application Availability: Platform SREs need to drain and upgrade Kubernetes worker nodes frequently (for kernel patching, Karpenter cost optimization, and EKS version upgrades). However, blindly evicting pods will drop user traffic. PodDisruptionBudgets (PDBs) establish the formal contract between platform operations and software availability.
  3. Automated Drift Self-Healing: AWS Config rules detect unauthorized manual changes in the AWS Console and trigger automated AWS Systems Manager (SSM) Automation runbooks to revert the violation in under 60 seconds without human intervention.

๐Ÿ—บ๏ธ Visual Architecture: Kubernetes Eviction API & PDB Lifecycle

sequenceDiagram
    autonumber
    actor SRE as ๐Ÿ‘จโ€๐Ÿ’ป SRE / Karpenter (Node Drain)
    participant Kubelet as โ˜ธ๏ธ Kubernetes API Server
    participant PDBController as ๐Ÿ›ก๏ธ PDB Controller (disruptionsAllowed)
    participant EvictionAPI as ๐Ÿšช Pod Eviction API
    participant WorkloadPod as ๐Ÿ“ฆ Payment Microservice (minAvailable: 2, replicas: 3)
    participant WorkerNode as ๐Ÿ–ฅ๏ธ Target Worker Node

    SRE->>Kubelet: kubectl drain node-01
    Kubelet->>EvictionAPI: Evict pod 'payment-pod-1' on node-01
    EvictionAPI->>PDBController: Check PDB policy 'payment-pdb'
    Note over PDBController: Active Replicas = 3<br/>minAvailable = 2<br/>disruptionsAllowed = 1 (3 - 2 = 1) โœ…
    PDBController-->>EvictionAPI: Eviction Permitted!
    EvictionAPI->>WorkloadPod: Send SIGTERM & delete pod
    WorkloadPod->>WorkerNode: Drain active connections & terminate
    
    Note over PDBController: Active Replicas = 2. disruptionsAllowed = 0 โ›”
    Kubelet->>EvictionAPI: Evict pod 'payment-pod-2' on node-01
    EvictionAPI->>PDBController: Check PDB policy 'payment-pdb'
    PDBController-->>EvictionAPI: Error: HTTP 429 Too Many Requests (PDB Violated) โŒ
    EvictionAPI-->>Kubelet: Cannot evict! Retrying until replacement pod is healthy...

๐Ÿ”ฌ Under the Hood: PDB Mathematics & disruptionsAllowed

A PodDisruptionBudget limits the number of pods of a replicated application that can be down simultaneously during voluntary disruptions (e.g. kubectl drain, node scale-in, or cluster upgrades):

๐Ÿ“ disruptionsAllowed = Current Healthy Pods - minAvailable

  • Calculation Principle: If a service has 5 healthy running pods and minAvailable: 4, then disruptionsAllowed = 5 - 4 = 1. The Eviction API allows draining 1 node. If only 4 pods are running, disruptionsAllowed = 0, and kubectl drain will block until a new pod becomes healthy.

Real-Time PDB Diagnostic Inspection

# Inspect live disruptionsAllowed status across all namespaces
kubectl get pdb -A

# Sample Output:
# NAMESPACE    NAME                 MIN AVAILABLE   MAX UNAVAILABLE   ALLOWED DISRUPTIONS   AGE
# workloads    payment-service-pdb  2               N/A               1                     45d
# workloads    order-service-pdb    80%             N/A               2                     12d

Voluntary vs. Involuntary Disruptions

  • Involuntary Disruptions (Unpreventable): Hardware failures on the physical AWS server, kernel panics, or accidental node terminations. PDBs cannot prevent hardware crashes.
  • Voluntary Disruptions (Protected by PDBs): kubectl drain executed by an engineer, node draining by Karpenter consolidation, cluster autoscaler scale-down, or EKS managed node group AMI upgrades.

๐Ÿ’ป Production Code: Hardened PDB & AWS Config Manifests

1. Production Kubernetes PodDisruptionBudget (pdb.yaml)

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: payment-service-pdb
  namespace: workloads
spec:
  minAvailable: 2 # Guarantees at least 2 pods remain healthy at all times
  selector:
    matchLabels:
      app: payment-service

2. AWS Config Rule with Automated Remediation (Terraform)

Enforces that every EBS volume created in the account has KMS encryption enabled; automatically initiates remediation if an unencrypted volume is created:

# 1. AWS Config Managed Rule for EBS Encryption
resource "aws_config_config_rule" "encrypted_volumes" {
  name        = "encrypted-volumes-check"
  description = "Checks whether EBS volumes are encrypted with KMS."

  source {
    owner             = "AWS"
    source_identifier = "ENCRYPTED_VOLUMES"
  }
}

# 2. Automated Remediation Configuration
resource "aws_config_remediation_configuration" "remediate_unencrypted_ebs" {
  config_rule_name = aws_config_config_rule.encrypted_volumes.name
  target_type      = "SSM_DOCUMENT"
  target_id        = "AWSConfigRemediation-EnableEbsEncryptionByDefault"

  automatic                  = true
  maximum_automatic_attempts = 3
  retry_attempt_seconds      = 60

  parameters = {
    AutomationAssumeRole = {
      static_value = "arn:aws:iam::123456789012:role/ConfigRemediationExecutionRole"
    }
  }
}

โš ๏ธ Real-World Failure Modes, Exceptions & Break-Glass Playbooks

Exception 1: The PDB Eviction Deadlock (The Infinite Hang Trap)

  • The Disaster: An SRE runs kubectl drain <node> --ignore-daemonsets during an urgent cluster upgrade. The terminal hangs indefinitely:
    evicting pod workloads/payment-pod-7d4f9
    error when evicting pod "payment-pod-7d4f9": Cannot evict pod as it would violate the pod's disruption budget.
    waiting for pod workloads/payment-pod-7d4f9 to be deleted...
  • The Root Cause: The application deployment was scaled down to 2 replicas, and its PDB declares:
    minAvailable: 2
    Because only 2 replicas exist, evicting 1 pod would reduce capacity to 1, violating minAvailable: 2. The Kubernetes API server returns HTTP 429 Too Many Requests. kubectl drain enters an infinite polling retry loop! The SRE cannot drain the node, Karpenter cannot consolidate, and cluster patching stalls.
  • The Architectural Exception Patterns:
    1. Pattern A: Use maxUnavailable: 1 instead of minAvailable: If you scale down to 1 replica, maxUnavailable: 1 still permits evicting the pod, whereas minAvailable: 2 deadlocks completely!
    2. Pattern B: Modern Kubernetes 1.28+ Force Drain:
      # Kubernetes 1.28+ supports bypassing the Eviction API in emergencies:
      kubectl drain <node> --ignore-daemonsets --delete-emptydir-data --disable-eviction=true
    3. Pattern C: Break-Glass Temporary PDB Patching:
      # Temporarily patch PDB minAvailable to 1 during the maintenance window:
      kubectl patch pdb payment-service-pdb -n workloads --type='json' -p='[{"op": "replace", "path": "/spec/minAvailable", "value": 1}]'

Exception 2: The Single-Replica Workload PDB Trap

  • The Anti-Pattern: A developer creates a single-replica batch processing deployment (replicas: 1) and creates a PDB with minAvailable: 1 or maxUnavailable: 0.
  • The Failure: The pod can never be voluntarily evicted! Any attempt to drain the node running this pod will hang forever, preventing OS kernel patching on that physical machine.
  • The Policy Enforcement (Kyverno): Deploy a Kyverno validating policy that rejects any PodDisruptionBudget where minAvailable == replica_count when replica_count < 2.

๐Ÿ“ Staff Architect & SRE Interview Scenarios

โ“ ๐ŸŸข Low Difficulty: `minAvailable` vs `maxUnavailable` in PDBs

Question: What is the technical difference between declaring minAvailable: 80% versus maxUnavailable: 20% in a Kubernetes PodDisruptionBudget?

Answer: Both express availability thresholds, but they calculate budgets differently:

  • minAvailable: 80%: Instructs the eviction controller that at least 80% of desired pods must remain healthy and ready. If you have 5 pods, 5 ร— 0.8 = 4 pods must be healthy (allowing 1 eviction).
  • maxUnavailable: 20%: Explicitly caps the number of pods that can be unavailable simultaneously.
  • Key Difference in Scaling: If an application scales from 10 replicas down to 2 replicas, minAvailable: 80% requires 2 ร— 0.8 = 1.6 โ†’ 2 pods, meaning 0 disruptions allowed (deadlock risk!). maxUnavailable: 1 guarantees that at least 1 pod can always be evicted, preventing node drain deadlocks.
โ“ ๐ŸŸก Medium Difficulty: Detective vs Proactive Compliance

Question: In enterprise governance, what is the architectural difference between Detective controls (AWS Config) and Proactive controls (AWS CloudFormation Guard / OPA)?

Answer:

  • Proactive Controls (Shift-Left): Evaluated before resources are provisioned (e.g. OPA Rego in CI/CD or CloudFormation Guard hooks). Blocks non-compliant resources from ever being created in the cloud.
  • Detective Controls (Runtime): Continuously monitors the live cloud environment after provisioning (e.g. AWS Config). Captures out-of-band drift created manually in the AWS Console or via external APIs, generating compliance audit logs and triggering automated remediation.
  • Enterprise Rule: High-trust architectures require both (Defense-in-Depth).
โ“ ๐Ÿ”ด Hard Difficulty: How Does Karpenter Interact with PDBs?

Question: How does Karpenterโ€™s automated node consolidation engine evaluate PodDisruptionBudgets when choosing which EC2 worker nodes to terminate for cost optimization?

Answer: Karpenter uses the standard Kubernetes Eviction API. When identifying an underutilized node to terminate, Karpenter simulates the eviction of all pods on that node against their respective PDBs. If any pod on the candidate node has a PDB with disruptionsAllowed: 0, Karpenter abandons consolidation on that node and moves on to other candidates. Karpenter will never terminate a node if doing so violates an applicationโ€™s PDB, preventing automated cost optimization from causing production availability outages.

โ“ ๐ŸŸฃ Complex Difficulty: Eviction API Rate Limiting & Thundering Herd

Question: During a mass cluster drain of 50 worker nodes simultaneously, why does the Kubernetes Eviction API return HTTP 429 errors, and how does the cluster prevent a cascading crash?

Answer: The Eviction API is an admission subresource (POST /api/v1/namespaces/{ns}/pods/{name}/eviction). When 50 nodes drain concurrently, thousands of eviction requests bombard the kube-apiserver. The PDB controller evaluates disruptionsAllowed in real time.

If 10 pods belonging to the same microservice are scheduled across those 50 nodes, and the PDB allows only 1 disruption at a time, 9 of the eviction calls are rejected with HTTP 429 Too Many Requests. The draining controller backs off exponentially. Once the replacement pod launches on a new node and passes its readiness probe (readinessProbe: HTTP 200), the PDB controller increments disruptionsAllowed from 0 back to 1, allowing the next eviction call to succeed. This self-throttling loop protects the application from being overwhelmed during mass node rotation.