Skip to content

Instantly share code, notes, and snippets.

@muhammad-asn
Created October 6, 2025 02:28
Show Gist options
  • Save muhammad-asn/ae260a242821c1716fea27c40d5aba5e to your computer and use it in GitHub Desktop.
Save muhammad-asn/ae260a242821c1716fea27c40d5aba5e to your computer and use it in GitHub Desktop.
One Liner get kubernetes pvcs and their zone
#!/bin/bash
echo "NAMESPACE PVC PV ZONE"; kubectl get pvc -A -o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{" "}{.spec.volumeName}{"\n"}{end}' | while read ns pvc pv; do echo -n "$ns $pvc $pv "; kubectl get pv "$pv" -o jsonpath='{.spec.nodeAffinity.required.nodeSelectorTerms[*].matchExpressions[?(@.key=="topology.kubernetes.io/zone")].values[*]}' 2>/dev/null; echo; done | column -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment