<p>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?</p>

J. Ike
<p>Have you taken a look at this library? <br>
<a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">https://github.com/kubernetes-client/python</a></p>
<p>Utilizing the above library, the way that I would do to achieve what you want is:</p>
<pre class="lang-py prettyprint-override"><code>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(&quot;Listing StatefulSets' labels:&quot;)
ret = v1.list_stateful_set_for_all_namespaces(watch=False)
for i in ret.items:
    print(i.metadata.labels)
</code></pre>
