Skip to content

Instantly share code, notes, and snippets.

@TJM
Last active July 11, 2023 03:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TJM/c65292987937b387741c0b529f5aa1ac to your computer and use it in GitHub Desktop.
Save TJM/c65292987937b387741c0b529f5aa1ac to your computer and use it in GitHub Desktop.
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