[英]Get details of persistent volume claim using python k8s client
I'm trying to get details of persistentvolumeclaim such as "Used By" which you can get when you run kubectl describe pvc [your-pvc-name]
but I'm trying to get that using python k8s client.我正在尝试获取persistentvolumeclaim的详细信息,例如当您运行
kubectl describe pvc [your-pvc-name]
时可以获得的“Used By” ,但我正在尝试使用 python k8s 客户端来获取它。 I'm able to get YAML of the pvc through readNamespacedPersistentVolumeClaim()
function but it doesn't contain the "Used By" .我能够通过
readNamespacedPersistentVolumeClaim()
function 获得 pvc 的 YAML 但它不包含"Used By" 。 How to use python k8s client to get details of a persistentvolumeclaim such as "Used By" .如何使用 python k8s 客户端获取 persistentvolumeclaim 的详细信息,例如“Used By” 。
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
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.这段代码似乎可以完美地列出命名空间中的所有 pod 及其各自的 pvc,我们可以从中过滤掉我们想要的 pod。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.