Skip to content

Instantly share code, notes, and snippets.

@devnulled
Last active September 18, 2018 20:43
Show Gist options
  • Save devnulled/d1993a45bc87643a03a76c6dcd51d125 to your computer and use it in GitHub Desktop.
Save devnulled/d1993a45bc87643a03a76c6dcd51d125 to your computer and use it in GitHub Desktop.
Run A Command Against a Collection of Kubernetes Resources
# 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