<p>For example I have StatefulSet with custom labels/annotations applied on it.</p>
<p>Everyone mentions these two metrics should be used, because <code>kube-state-metrics</code> should generate labels/annotations as well.</p>
<pre><code>kube_statefulset_annotations
kube_statefulset_labels
</code></pre>
<p>The thing is, I can see only default ones (<code>job</code>,<code>instance</code>, <code>namespace</code>,...) but not additionally added labels/annotations.</p>
<p>Example of the manifest I am testing with:</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
    label_network: &quot;111&quot;
  labels:
    app: testing-labels
    label_STATEFULSET_LABEL: &quot;111&quot;
    label_network: &quot;111&quot;
  name: testing-labels
  namespace: sre-test
spec:
  selector:
    matchLabels:
      app: testing-labels
  serviceName: testing-labels-headless
  template:
    metadata:
      labels:
        app: testing-labels
        label_network: &quot;111&quot;
</code></pre>
<p>I've added so many different labels/annotations but the <code>kube_statefulset_labels{statefulset='testing-labels'}</code> returns:</p>
<blockquote>
<p>kube_statefulset_labels{container=&quot;kube-rbac-proxy-main&quot;, instance=&quot;10.2.23.229:8443&quot;, job=&quot;kube-state-metrics&quot;, namespace=&quot;sre-test&quot;, prometheus=&quot;aws-monitoring/k8s&quot;, prometheus_replica=&quot;prometheus-k8s-1&quot;, statefulset=&quot;testing-labels&quot;}</p>
</blockquote>
<p>...which certainly doesn't contain any extra label. Any idea would be helpful? 🙏🏼</p>
<h3>Versions:</h3>
<ul>
<li>kube-state-metrics:v2.5.0</li>
<li>kube-rbac-proxy:v0.12.0</li>
</ul>

Ivan Aracki
<p>In order to get custom metrics within <code>kube_statefulset_labels</code> we need to add</p>
<p><code>--metric-labels-allowlist</code> as a flag in kube-state-metrics. (<a href="https://github.com/kubernetes/kube-state-metrics/blob/master/docs/cli-arguments.md#available-options" rel="nofollow noreferrer">docs</a>)</p>
<p>In this particular example it would be:</p>
<pre><code>--metric-labels-allowlist=statefulsets=[label_network]
</code></pre>
