Skip to content

Instantly share code, notes, and snippets.

@dleehr
Created August 8, 2019 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dleehr/c8ba6ad1303d47bfa434b85f53ce3f28 to your computer and use it in GitHub Desktop.
Save dleehr/c8ba6ad1303d47bfa434b85f53ce3f28 to your computer and use it in GitHub Desktop.
Script for one-off pod to mount a PVC
#!/bin/bash
set -eo pipefail
NAMESPACE=$1
PVC=$2
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <namespace> <pvc-name>"
exit 1
fi
kubectl run --rm -n $NAMESPACE --attach=true -i attach-${PVC} --overrides='
{
"spec": {
"containers": [
{
"name": "attach",
"image": "debian:stretch-slim",
"workingDir": "/attached",
"command": ["bash"],
"stdin": true,
"stdinOnce": true,
"tty": true,
"volumeMounts": [
{ "mountPath": "/attached", "name": "attached", "readOnly": false }
]
}
],
"restartPolicy": "Never",
"volumes": [
{ "name": "attached", "persistentVolumeClaim": {"claimName": "'${PVC}'" } }
]
}
}
' --image=debian:stretch-slim --restart=Never
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment