<p>Is there a way to get the replica count at runtime within a pod that belongs to a StatefulSet?
I have verified that the following answer <a href="https://stackoverflow.com/a/54306021/5514015">https://stackoverflow.com/a/54306021/5514015</a> gives you the hostname of the pod, which includes the pod ordinal number, at runtime, but I would also like to know the number of replicas configured in the StatefulSet. Is this possible to determine?</p>

jim
<p>Unfortunately, the number of replicas is not available through the <a href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#capabilities-of-the-downward-api" rel="nofollow noreferrer">Downward API</a>. But in a <code>StatefulSet</code>, as you say, it is common to need this number.</p>
<p>Proposed ways to get the number:</p>
<ul>
<li>Implement this within your app so that they coordinate, and perhaps can find out it through <em>ordinal</em> identities.</li>
<li>Alternatively let your app communicate with the Kubernetes API Server using e.g. <a href="https://github.com/kubernetes/client-go" rel="nofollow noreferrer">client-go</a>, but this ties your application to Kubernetes.</li>
</ul>
<p>For reliability, you might want to design your app in a way so that it can work (at least for some time) without the Kubernetes control-plane being available, so I would recommend to implement this without the Kubernetes API e.g. the first solution above.</p>
