HorizontalPodAutoscaler - Scale Deployment in Another Namespace

6/26/2018

I'm attempting to get autoscaling set up using custom metrics.

Currently, I have:

  • Prometheus Operator running in the monitoring namespace.
  • K8S Prometheus Adapter running in the custom-metrics namespace, exposed through a service named api.
  • A deployment running in the my-namespace namespace.

I added a HorizontalPodAutoscaler in the custom-metrics namespace, targeting my deployment.

The YAML looks like:

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

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

Does Kubernetes expect that the custom metrics API, the scale target and the HorizontalPodAutoscaler all exist in the same namespace?

-- user265312
kubernetes

1 Answer

6/26/2018

Yes, Deployment which you want to scale should be in the same namespace with HorizontalPodAutoscaler object.

Here is an extract from the Kubernetes documentation:

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

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

-- Akar
Source: StackOverflow