0

I am trying to find an API function to read the keys and values of all the labels in a kubernetes statefulset. Can anyone point me to an example or documentation on how this can be done?

J. Ike
  • 19
  • 5

1 Answers1

1

Have you taken a look at this library?
https://github.com/kubernetes-client/python

Utilizing the above library, the way that I would do to achieve what you want is:

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)
Ruli
  • 2,592
  • 12
  • 30
  • 40
Hartono Wen
  • 116
  • 5