Skip to content

Instantly share code, notes, and snippets.

@zakkg3
Created September 5, 2019 15:45
Show Gist options
  • Save zakkg3/8c4f6b5e015d1229bf0643156b30ecdc to your computer and use it in GitHub Desktop.
Save zakkg3/8c4f6b5e015d1229bf0643156b30ecdc to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python3
from kubernetes import client, config
import sys
config.load_kube_config()
def print_help():
print('I need the namespace(s) as an argument')
if len(sys.argv) <= 1:
print (f'bad arguments: {str(sys.argv[1:])}')
print_help()
exit(1)
namespaces = sys.argv[1:]
v1 = client.CoreV1Api()
print ('Pods with Persistant Volume Cliams | namespace | pod | pvc')
for n in namespaces:
ret = v1.list_namespaced_pod(n,watch=False)
for i in ret.items:
for v in i.spec.volumes:
if v.persistent_volume_claim:
print (f'{n} | {i.metadata.name} | {v.persistent_volume_claim.claim_name}')
@zakkg3
Copy link
Author

zakkg3 commented Sep 5, 2019

Output:

>podwithpvclist.py gitlab mattermost
Pods with Persistant Volume Cliams. Output: namespace | pod | pvc
gitlab | gitlab-gitaly-0 | repo-data-gitlab-gitaly-0
gitlab | gitlab-minio-75567fcbb6-sxtkd | gitlab-minio
gitlab | gitlab-postgresql-66d8d9574b-s7wrc | gitlab-postgresql
gitlab | gitlab-redis-7668c4d476-c94rb | gitlab-redis
mattermost | mattermost-mattermost-team-edition-5486ff87d9-j6bjv | mattermost-mattermost-team-edition
mattermost | mattermost-mysql-748bb64ffb-rzr47 | mattermost-mysql

@alikhanxgrid
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment