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?
Have you taken a look at this library? <br> 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)