【持續更新】Client-Python for Kubernetes API

【持續更新】Client-Python for Kubernetes API

來自專欄 開發運維

From source:

git clone --recursive https://github.com/kubernetes-client/python.gitcd pythonpython setup.py install

From PyPi directly:

pip install kubernetes

Example

list all pods:

from kubernetes import client, config# Configs can be set in Configuration class directly or using helper utilityconfig.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 %s %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 utilityconfig.load_kube_config()v1 = client.CoreV1Api()count = 10w = 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 整理,敬請期待,歡迎有感興趣的同學加入小組。

推薦閱讀:

什麼樣的運維工程師薪水較高, 你知道嗎?
關於DevOps你必須知道的11件事
網路喚醒全攻略(Wake On LAN)
高德地圖基於阿里雲MaxCompute的最佳實踐
QQ 相冊後台存儲架構重構與跨 IDC 容災實踐

TAG:Kubernetes | Python | 運維 |