Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Write a PodDisruptionBudget and topology spread so node drains never take the app down.

IntermediateHands-onWrite-a-Kubernetes-manifest tasks
Answer
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: { name: api }
spec:
  minAvailable: 2
  selector: { matchLabels: { app: api } }
---
# in the Deployment pod template
spec:
  topologySpreadConstraints:
    - maxSkew: 1
      topologyKey: topology.kubernetes.io/zone
      whenUnsatisfiable: ScheduleAnyway
      labelSelector: { matchLabels: { app: api } }

Key trick → The PDB stops kubectl drain from evicting below 2 ready pods, and the spread puts replicas in different zones. With replicas: 2 and minAvailable: 2, a drain blocks forever, so leave room.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks