0

我正在尝试找到一个 API 函数来读取 kubernetes statefulset 中所有标签的键和值。谁能指出我如何做到这一点的示例或文档?

4

1 回答 1

1

你看过这个图书馆吗?
https://github.com/kubernetes-client/python

利用上面的库,我实现你想要的方式是:

from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()

v1 = client.AppsV1Api()
print("Listing StatefulSets' labels:")
ret = v1.list_stateful_set_for_all_namespaces(watch=False)
for i in ret.items:
    print(i.metadata.labels)
于 2021-10-26T03:18:02.217 回答