k8s: PersistentVolumeClaim satisfier
The snippet can be accessed without any authentication.
Authored by
Furkan Mustafa
This script generates PersistentVolume
s using hostPath
for all pending PVCs.
Volumes will be places under $PVROOTDIR/$NAMESPACE/$PVC-NAME
by default; PVROOTDIR=/srv/tmp-volumes
#!/bin/sh -e
PVROOTDIR=/srv/tmp-volumes
# Volumes will be places under $PVROOTDIR/$NAMESPACE/$PVC-NAME
makevol() {
cat <<EOF
apiVersion: v1
kind: PersistentVolume
metadata:
name: $2
namespace: $1
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: $3
# volumeMode: Filesystem
hostPath:
path: $PVROOTDIR/$1/$2
EOF
}
kubectl get pvc --all-namespaces | grep Pending | while read pvc; do
namespace=$(echo $pvc | awk '{ print $1 }')
name=$(echo $pvc | awk '{ print $2 }')
size=$(kubectl get pvc/$name -n $namespace -o=yaml | grep -A1 "requests" | grep "storage:" | awk '{ print $2}')
echo "PVC: $name@$namespace"
makevol $namespace $name $size | kubectl apply -f -
done
Please register or sign in to comment