<p>I have a statefulset and I need to know what is the current replica count from inside the pod. To do so, I tried:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: sample-mariadb
  namespace: demo
spec:
  replicas: 3
  template:
    spec:
      containers:
      - env:
        - name: REPLICAS
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.replicas
</code></pre>
<p>and got this error:</p>
<blockquote>
<p>Warning  FailedCreate      4m15s (x17 over 9m43s)  statefulset-controller  create Pod sample-mariadb-0 in StatefulSet sample-mariadb failed error: Pod &quot;sample-mariadb-0&quot; is invalid: spec.containers[1].env[3].valueFrom.fieldRef.fieldPath: Invalid value: &quot;spec.replicas&quot;: error converting fieldPath: field label not supported: spec.replicas</p>
</blockquote>
<p>How can I get current replica count from inside the pod?</p>

Alif Biswas
<p>You can only send the fields that are part of Pod specification. The <code>spec.replicas</code> field is part of StatefulSet specification not the underlying pod's. The <code>template</code> part of a StatefulSet is the pod specification. Hence, you are getting this error.</p>
