Skip to content

Instantly share code, notes, and snippets.

@kevsmith
Created May 3, 2022 19:54
Show Gist options
  • Save kevsmith/72dd5e924f4ccd30487c9ba42857c8a8 to your computer and use it in GitHub Desktop.
Save kevsmith/72dd5e924f4ccd30487c9ba42857c8a8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Helper script to clean all persistent volumes (PVs) and persistent volume claims (PVCs)
# from a minikube-based environment.
# First let's clean persistent volume claims
# Get the total lines and subtract one for the header
total=$(expr $(kubectl --context minikube get pvc | wc -l) - 1)
# Iterate over each PVC and delete
for pvc in $(kubectl --context minikube get pvc | tail -n${total} | cut -d' ' -f1)
do
kubectl --context minikube delete pvc ${pvc}
done
# Now let's do the underlying persistent volumes
total=$(expr $(kubectl --context minikube get pv | wc -l) - 1)
for pv in $(kubectl --context minikube get pv | tail -n${total} | cut -d' ' -f1)
do
kubectl --context minikube delete pv ${pv}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment