Interview Prep/Kubernetes/Storage and volumes

Someone deleted a namespace and the database PVs and their EBS volumes were deleted with it.

AdvancedTroubleshootingStorage and volumes
Answer

Likely causes → The StorageClass had reclaimPolicy: Delete (the default for dynamically provisioned volumes), so deleting the PVC deleted the PV and the cloud disk.

Diagnose →

kubectl get sc -o custom-columns=NAME:.metadata.name,RECLAIM:.reclaimPolicy
aws ec2 describe-snapshots --owner-ids self --filters Name=tag:kubernetes.io/created-for/pvc/name,Values=data-db-0

Fix → Restore from the latest snapshot or Velero backup into new PVCs. For surviving volumes, switch reclaim policy now:

kubectl patch pv <pv> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'

Prevent → Retain StorageClass for stateful data, scheduled snapshots, RBAC that limits namespace deletion, and an admission policy blocking deletes of protected namespaces.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Storage and volumes