Is it possible to use kubernetes python client library in order to get output similar to kubectl describe nodes ?
Is it possible to use kubernetes python client library in order to get output similar to kubectl describe nodes ?
Yes, you can use it to do the same task mostly you are doing with kubectl.
kubectl itself is one type of client that you are using.
Example :
from kubernetes import client, config
def main():
config.load_kube_config()
api_instance = client.CoreV1Api()
# Listing the cluster nodes
node_list = api_instance.list_node()
print("%s\t\t%s" % ("NAME", "LABELS"))
if __name__ == '__main__':
main()
Example ref : https://github.com/kubernetes-client/python/blob/master/examples/node_labels.py
EDIT
res_pods = v1.list_pod_for_all_namespaces(pretty=True)
for i in res_pods.items:
for j in i.spec.containers:
if j.resources.requests or j.resources.limits:
print(i.spec.node_name, j.name, j.resources)