Skip to content

Instantly share code, notes, and snippets.

@srkiNZ84
Created January 10, 2018 02:22
Show Gist options
  • Save srkiNZ84/3c8412067840df5b08c28a47f2d6fb77 to your computer and use it in GitHub Desktop.
Save srkiNZ84/3c8412067840df5b08c28a47f2d6fb77 to your computer and use it in GitHub Desktop.
Python script to list Kubernetes deployments
#!/usr/bin/python
from kubernetes import client, config
# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config(context="foobar")
#v1 = client.CoreV1Api()
v1 = client.AppsV1beta1Api()
print("Listing deployments with their IPs:")
ret = v1.list_deployment_for_all_namespaces(watch=False)
for i in ret.items:
print("\n%s\n" % (i.spec.template.spec.containers[0].image))
print("%s\t%s\t%s\t%s" % (i.status, i.metadata.namespace,\
i.metadata.name, i.metadata.labels.get('version',"None")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment