<p>I am trying to autoscale my StatefulSet on Kubernetes. In order to do so, I need to get the current number of pods.</p>

<p>When dealing with deployments:</p>

<pre><code>kubectl describe deployments [deployment-name] | grep desired | awk '{print $2}' | head -n1
</code></pre>

<p>This outputs a number, which is the amount of current deployments.</p>

<p>However, when you run </p>

<pre><code>kubectl describe statefulsets
</code></pre>

<p>We don't get back as much information. Any idea how I can get the current number of replicas of a stateful set?</p>

DUDANF
<pre><code> kubectl get sts web -n default -o=jsonpath='{.status.replicas}'
</code></pre>

<p>This also works with .status.readyReplicas and .status.currentReplicas</p>

<p>From <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/apps/types.go" rel="noreferrer">github.com/kubernetes</a>:</p>

<blockquote>
  <p>// replicas is the number of Pods created by the StatefulSet controller.<br>
  Replicas int32</p>
  
  <p>// readyReplicas is the number of Pods created by the StatefulSet controller that have a Ready Condition.<br>
  ReadyReplicas int32</p>
  
  <p>// currentReplicas is the number of Pods created by the StatefulSet controller from the StatefulSet version<br>
  // indicated by
  currentRevision.<br>
  CurrentReplicas int32</p>
</blockquote>
