I'm attempting to get autoscaling set up using custom metrics.
Currently, I have:
monitoring
namespace.custom-metrics
namespace, exposed through a service named api
.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?
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.