<p>I am trying to setup HPA for my statefulset(for elasticsearch) in kubernetes environment. I am planning to scale the statefulset using the cpu utilization. I have created the metric server from <a href="https://github.com/stefanprodan/k8s-prom-hpa/tree/master/metrics-server" rel="noreferrer">https://github.com/stefanprodan/k8s-prom-hpa/tree/master/metrics-server</a>.</p>

<p>and my HPA yaml for statefulset is as folows:</p>

<pre><code>apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: dz-es-cluster
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: StatefulSet
    name: dz-es-cluster
  minReplicas: 2
  maxReplicas: 3
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 80
</code></pre>

<p>But getting output in hpa as follows:</p>

<pre><code>Conditions:
  Type         Status  Reason          Message
  ----         ------  ------          -------
  AbleToScale  False   FailedGetScale  the HPA controller was unable to get the target's current scale: the server could not find the requested resource
Events:
  Type     Reason          Age                From                       Message
  ----     ------          ----               ----                       -------
  Warning  FailedGetScale  1m (x71 over 36m)  horizontal-pod-autoscaler  the server could not find the requested resource
</code></pre>

<p>someone please help me..</p>

manu thankachan
<p>The support for autoscaling the statefulsets using HPA is added in kubernetes 1.9, so your version doesn't has support for it. After kubernetes 1.9, you can autoscale your statefulsets using:</p>

<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: YOUR_HPA_NAME
spec:
  maxReplicas: 3
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: StatefulSet
    name: YOUR_STATEFUL_SET_NAME
  targetCPUUtilizationPercentage: 80
</code></pre>

<p>Please refer the following link for more information:</p>

<blockquote>
  <p><a href="https://github.com/kubernetes/kubernetes/issues/44033" rel="noreferrer">https://github.com/kubernetes/kubernetes/issues/44033</a></p>
</blockquote>
