K8S查看pod和pvc的绑定关系

先安装jq:

[root@localhost ~]# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
 
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm
 
[root@localhost ~]# yum repolist      ##检查是否已添加至源列表

[root@localhost ~]# yum install jq -y
[root@k8s01 ~]# cat pvc-pod.sh
kubectl get pods --all-namespaces -o=json | jq -c '.items[] | {name: .metadata.name, namespace: .metadata.namespace, claimName:.spec.volumes[] | select( has ("persistentVolumeClaim") ).persistentVolumeClaim.claimName }'
[root@k8s01 ~]# sh pvc-pod.sh
{"name":"wordpress-6f876869f-sfjkv","namespace":"default","claimName":"wp-pv-claim"}
{"name":"wordpress-mysql-6d9d576684-wlwdv","namespace":"default","claimName":"mysql-pv-claim"}
{"name":"jenkins2-7bb5944f54-vkk6z","namespace":"kube-ops","claimName":"opspvc"}
{"name":"elasticsearch-logging-0","namespace":"monitoring","claimName":"elasticsearch-data-elasticsearch-logging-0"}
{"name":"elasticsearch-logging-1","namespace":"monitoring","claimName":"elasticsearch-data-elasticsearch-logging-1"}
{"name":"elasticsearch-logging-2","namespace":"monitoring","claimName":"elasticsearch-data-elasticsearch-logging-2"}
{"name":"grafana-7ccc6b94d5-s2tp9","namespace":"monitoring","claimName":"grafana-pvc"}
{"name":"prometheus-server-0","namespace":"monitoring","claimName":"prometheus-data-prometheus-server-0"}
{"name":"prometheus-server-1","namespace":"monitoring","claimName":"prometheus-data-prometheus-server-1"}
{"name":"prometheus-server-2","namespace":"monitoring","claimName":"prometheus-data-prometheus-server-2"}

你可能感兴趣的:(K8S,kubernetes)