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.
More on Write-a-Kubernetes-manifest tasks
Write a Deployment and Service for an Nginx app with 3 replicas, resources and probes.BeginnerAdd an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.BeginnerFix this broken Deployment YAML.BeginnerWrite a ConfigMap and Secret and inject them as environment variables and as a mounted file.IntermediateWrite an Ingress that routes `/api` to the api service and `/` to the web service with TLS.IntermediateWrite a pod spec with a hardened securityContext.Intermediate