Created
December 4, 2024 11:16
-
-
Save jplitza/edf0b6ae2535eb278f96e9147dc03f2d to your computer and use it in GitHub Desktop.
Resize PersistentVolumeClaims according to owning StatefulSet spec
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
#!/bin/sh -eu | |
# Update the actual storage requets of existing PVCs to those specified in their owning StatefulSet. | |
# This assumes the StatefulSet was already "updated" (via `kubectl replace --force --cascade=orphan` or similar) | |
STS="$1" | |
kubectl get statefulset "$STS" -o jsonpath='{range .spec.volumeClaimTemplates[]}{.metadata.name} {.spec.resources.requests.storage}{"\n"}{end}' | | |
while read -r VOLNAME SIZE; do | |
for PVC in $(kubectl get pvc -o custom-columns=NAME:.metadata.name | grep -E "^$VOLNAME-$STS-[0-9]+\$"); do | |
kubectl patch pvc "$PVC" -p '{"spec": {"resources": {"requests": {"storage": "'"$SIZE"'"}}}}' > /dev/null | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment