{
  "id": "pod-disruption-budget-task",
  "title": "Configure a PodDisruptionBudget",
  "category": "Cluster Administration",
  "difficulty": "Medium",
  "type": "task",
  "weight": 6,
  "description": "## PodDisruptionBudget\n\nA **PodDisruptionBudget (PDB)** limits the number of pods of a replicated application that are down simultaneously during voluntary disruptions (node drains, cluster upgrades). It is a critical CKA topic.\n\n**Your task:**\n\nA Deployment named `pdb-app` with **3 replicas** is already running. Create a **PodDisruptionBudget** named `web-pdb` in the `default` namespace that:\n- Applies to pods with the label `app=pdb-app`\n- Ensures **at least 2 pods** are always available (`minAvailable: 2`)\n\n```bash\n# Verify:\nkubectl get pdb web-pdb\n```",
  "hints": [
    {
      "title": "PodDisruptionBudget manifest",
      "body": "Use `spec.minAvailable` (integer or percentage) and `spec.selector.matchLabels` to target the right pods.",
      "command": "cat <<EOF | kubectl apply -f -\napiVersion: policy/v1\nkind: PodDisruptionBudget\nmetadata:\n  name: web-pdb\nspec:\n  minAvailable: 2\n  selector:\n    matchLabels:\n      app: pdb-app\nEOF"
    },
    {
      "title": "Check the PDB status",
      "body": "After creating the PDB, check `kubectl get pdb web-pdb` — the ALLOWED DISRUPTIONS column shows how many pods can be disrupted at once.",
      "command": "kubectl get pdb web-pdb -o wide"
    }
  ],
  "setup_commands": [
    {
      "command": "kubectl create deployment pdb-app --image=nginx:alpine --replicas=3 2>/dev/null || true"
    },
    {
      "command": "kubectl rollout status deployment/pdb-app --timeout=90s"
    }
  ],
  "validation": {
    "commands": [
      {
        "description": "PDB 'web-pdb' exists",
        "command": "kubectl get pdb web-pdb -o jsonpath='{.metadata.name}'",
        "expected_output": "web-pdb",
        "match": "exact"
      },
      {
        "description": "minAvailable is 2",
        "command": "kubectl get pdb web-pdb -o jsonpath='{.spec.minAvailable}'",
        "expected_output": "2",
        "match": "exact"
      },
      {
        "description": "PDB selector targets app=pdb-app",
        "command": "kubectl get pdb web-pdb -o jsonpath='{.spec.selector.matchLabels.app}'",
        "expected_output": "pdb-app",
        "match": "exact"
      },
      {
        "description": "Deployment 'pdb-app' has 3 replicas",
        "command": "kubectl get deployment pdb-app -o jsonpath='{.spec.replicas}'",
        "expected_output": "3",
        "match": "exact"
      }
    ]
  },
  "default_namespace": "default",
  "teardown_commands": [
    {
      "command": "kubectl delete pdb web-pdb --ignore-not-found"
    },
    {
      "command": "kubectl delete deployment pdb-app --ignore-not-found"
    }
  ]
}
