Last active
September 18, 2018 20:43
-
-
Save devnulled/d1993a45bc87643a03a76c6dcd51d125 to your computer and use it in GitHub Desktop.
Run A Command Against a Collection of Kubernetes Resources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example of running a command against each persistantvolume of a given storage class in CoolBrosNetes | |
# Grab the JSON to parse from k8s | |
kubectl get pv -o json > pv.json | |
# Parse the JSON with jq and run that shit | |
jq -r '.items[] | select(.spec.storageClassName=="my-storage-class") | [.metadata.name] | @tsv' pv.json | | |
while IFS=$'\t' read -r name; do | |
echo The name is $name | |
done | |
# Delete all Released or Failed pvs | |
kubectl get pv -o json > pv.json | |
jq -r '.items[] | select((.status.phase=="Released") or .status.phase=="Failed") | [.metadata.name] | @tsv' pv.json | | |
while IFS=$'\t' read -r name; do | |
kubectl delete pv $name | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment