Skip to content

Instantly share code, notes, and snippets.

@jplitza
Created December 4, 2024 11:16
Show Gist options
  • Save jplitza/edf0b6ae2535eb278f96e9147dc03f2d to your computer and use it in GitHub Desktop.
Save jplitza/edf0b6ae2535eb278f96e9147dc03f2d to your computer and use it in GitHub Desktop.
Resize PersistentVolumeClaims according to owning StatefulSet spec
#!/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