Skip to content

Instantly share code, notes, and snippets.

@khaled
Last active March 1, 2022 10:04
Show Gist options
  • Save khaled/c2109f516c3775db0bdafa9e574cec52 to your computer and use it in GitHub Desktop.
Save khaled/c2109f516c3775db0bdafa9e574cec52 to your computer and use it in GitHub Desktop.
creates a temporary pod that can be use to inspect the contents of a kubernetes pvc. the pvc is mounted in the /data directory.
#!/bin/bash
#
# usage: ./volumeInspector.sh <pvc-name> <namespace>
#
# creates a temporary pod that can be use to inspect the contents
# of a pvc. the pvc is mounted in the /data directory.
#
#
# get pvcs in a namespace by running:
# kubectl get pvc -n <namespace>
#
read -r -d '' config <<-EOT
{
"kind": "Pod",
"apiVersion": "v1",
"spec": {
"volumes": [
{
"name": "vol",
"persistentVolumeClaim": {
"claimName": "$1"
}
}
],
"containers": [
{
"name": "inspector",
"image": "busybox",
"stdin": true,
"stdinOnce": true,
"tty": true,
"volumeMounts": [
{
"mountPath": "/data",
"name": "vol"
}
]
}
]
}
}
EOT
kubectl run -it --rm --image=busybox --restart=Never --overrides="$config" -n $2 -- bash
@maglub
Copy link

maglub commented Nov 4, 2020

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment