From source:
git clone --recursive https://github.com/kubernetes-client/python.git cd python python setup.py installFrom PyPi directly:
pip install kuberneteslist all pods:
from kubernetes import client, config # Configs can be set in Configuration class directly or using helper utility config.load_kube_config() v1 = client.CoreV1Api() print("Listing pods with their IPs:") ret = v1.list_pod_for_all_namespaces(watch=False) for i in ret.items: print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))watch on namespace object:
from kubernetes import client, config, watch # Configs can be set in Configuration class directly or using helper utility config.load_kube_config() v1 = client.CoreV1Api() count = 10 w = watch.Watch() for event in w.stream(v1.list_namespace, _request_timeout=60): print("Event: %s %s" % (event['type'], event['object'].metadata.name)) count -= 1 if not count: w.stop() print("Ended.")接下来持续更新client-Python for Kubernetes API 整理,敬请期待,欢迎有感兴趣的同学加入小组。