Debugging Kubernetes PVCs
While attempting to create a Tekton Pipeline consisting of multiple tasks recently, I was having a terrible time trying to work out what the various directory definitions were between tasks. These are pre-defined tasks so not ones that I had written myself and hence it can be a bit tricky to try to pick your way through all the various bits of yaml involved. What I really wanted to do (and what helped me debug the issue with my pipeline) was take a look at the content of the PVC (Persistent Volume Claim) that the pipeline was using.
Thanks to a really helpful post, it's quite simple to spin up a little pod that mounts your PVC.
You can then exec a shell into the pod and take a look around your PVC.
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: pvc-inspector
spec:
containers:
- image: busybox
name: pvc-inspector
command: ["tail"]
args: ["-f", "/dev/null"]
volumeMounts:
- mountPath: /pvc
name: pvc-mount
volumes:
- name: pvc-mount
persistentVolumeClaim:
claimName: pvc-name
EOF
The above will set up a pod that will stay running (thanks to the tail command) and mount your pvc "pvc-name" to /pvc, then all you need to do is start a shell
kubectl exec -it pvc-inspector -- sh
When you're done, you can exit and then delete the pod with
kubectl delete pod pvc-inspector