<p>I'm trying to get details of <strong>persistentvolumeclaim</strong> such as <strong>&quot;Used By&quot;</strong> which you can get when you run <code>kubectl describe pvc [your-pvc-name]</code> but I'm trying to get that using python k8s client. I'm able to get YAML of the pvc through <code>readNamespacedPersistentVolumeClaim()</code> function but it doesn't contain the <strong>&quot;Used By&quot;</strong>.
How to use python k8s client to get details of a persistentvolumeclaim such as <strong>&quot;Used By&quot;</strong>.</p>

Muhammad Ali Khan
<pre><code>from kubernetes import client


def get_pod_related_to_pvc(pvc_obj, pv_obj):
 v1 = client.CoreV1Api()
 pod = None
 pod_list = v1.list_namespaced_pod(pvc_obj.metadata.namespace)
 for pod in pod_list.items:
    for volume in pod.spec.volumes:
        if volume.persistent_volume_claim:
            if (volume.persistent_volume_claim.claim_name == pv_obj.spec.claimRef.name):
                return pod
</code></pre>
<p>This code seems to work perfectly  to list all pods with their respective pvc in a namespace from that we can filter out the pod we want.</p>
