<p>I'm attempting to get autoscaling set up using custom metrics.</p>

<p>Currently, I have:</p>

<ul>
<li><a href="https://github.com/coreos/prometheus-operator" rel="nofollow noreferrer">Prometheus Operator</a> running in the <code>monitoring</code> namespace.</li>
<li><a href="https://github.com/DirectXMan12/k8s-prometheus-adapter" rel="nofollow noreferrer">K8S Prometheus Adapter</a> running in the <code>custom-metrics</code> namespace, exposed through a service named <code>api</code>.</li>
<li>A deployment running in the <code>my-namespace</code> namespace.</li>
</ul>

<p>I added a <code>HorizontalPodAutoscaler</code> in the <code>custom-metrics</code> namespace, targeting my deployment.</p>

<p>The YAML looks like:</p>

<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: my-deployment-hpa
  namespace: custom-metrics
spec:
  maxReplicas: 10
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1beta2
    kind: Deployment
    name: my-deployment
  metrics:
  - type: Object
    object:
      metricName: queue_length
      targetValue: 1000
      target:
        apiVersion: extensions/v1beta1
        kind: Service
        name: api
</code></pre>

<p>When I describe the <code>HorizontalPodAutoscaler</code> via <code>kubectl describe hpa my-deployment-hpa -n custom-metrics</code>, I see <code>AbleToScale: False</code> because <code>FailedGetScale the HPA controller was unable to get the target's current scale: deployments/scale.extensions "my-deployment" not found</code>.</p>

<p>Does Kubernetes expect that the custom metrics API, the scale target and the <code>HorizontalPodAutoscaler</code> all exist in the same namespace?</p>

<p>Yes, <code>Deployment</code> which you want to scale should be in the same namespace with <code>HorizontalPodAutoscaler</code> object.</p>

<p>Here is an extract from the Kubernetes <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/" rel="nofollow noreferrer" title="Kubernetes Namespaces">documentation</a>:</p>

<blockquote>
  <p>Namespaces provide a scope for names. Names of resources need to be
  unique within a namespace, but not across namespaces.</p>
</blockquote>

<p>The <code>Namespace</code> value of the <code>HorizontalPodAutoscaler</code> object is the only way to provide information about namespace of deployment which you want to scale.</p>
