Kubernetes pvc in rwx monitoring

12/3/2021

I’ve a PVC in RWX. 2 pods use this PVC. I want to know which pods ask volume to the PVC and when. How can I manage that?

-- Wilson Wii
kubernetes
kubernetes-pvc
monitoring
persistent-volumes

1 Answer

12/3/2021

As far as i know there is no direct way to figure out a PVC is used by which pod To get that info possible workaround is grep through all the pods for the respective pvc :

Ex: 
- To display all the pods and their respective pvcs:
kubectl get pods -o jsonpath='{"POD"}{"\t"}{"PVC Name"}{"\n"}{range .items[*]}{.metadata.name}{"\t"}{range .spec.volumes[*]}{.persistentVolumeClaim.claimName}{"\t"}{end}{"\n"}{end}'

POD     PVC Name
web1-0  www1-web1-0
web16-0 www16-web16-0

- To get information about a particular PVC (in this case:www16-web16-0 ) Using grep :
kubectl get pods -o jsonpath='{"POD"}{"\t"}{"PVC Name"}{"\n"}{range .items[*]}{.metadata.name}{"\t"}{range .spec.volumes[*]}{.persistentVolumeClaim.claimName}{"\t"}{end}{"\n"}{end}' | grep 'POD\|www16-web16-0'
POD     PVC Name
web16-0 www16-web16-0
-- confused genius
Source: StackOverflow