Skip to content

Instantly share code, notes, and snippets.

@TJM
Last active May 19, 2020
Embed
What would you like to do?
K8s-Storage-shell - Connect to PVC with interactive shell
#!/bin/bash
#
# Start a debug-storage container mounting a specific volume (pvc)
#
IMAGE='centos:7'
if [ $# == 1 ]; then
PVC=$1
else
>&2 echo "ERROR: Please provide PVC to attach to"
exit 1
fi
kubectl run -it --rm=true --tty k8s-storage-shell --overrides='
{
"apiVersion": "v1",
"spec": {
"containers": [
{
"name": "shell",
"image": "'$IMAGE'",
"args": [
"bash"
],
"stdin": true,
"stdinOnce": true,
"tty": true,
"volumeMounts": [
{
"mountPath": "/data",
"name": "debug-storage"
}
]
}
],
"volumes": [
{
"name": "debug-storage",
"persistentVolumeClaim": {
"claimName": "'$PVC'"
}
}
]
}
}
' --restart=Never --image ${IMAGE} -- bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment