I have a custom metrics configured.
When I run:
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/my-namespace/deployments.extensions/sample-app/queue_length" | jq
I got:
...
"items": [
{
"describedObject": {
"kind": "Deployment",
"namespace": "my-namespace",
"name": "sample-app",
"apiVersion": "extensions/v1beta1"
},
"metricName": "queue_length",
"timestamp": "2018-10-09T18:14:15Z",
"value": "30"
}
]
...
So I want to scale my deployment with this metric:
kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
metadata:
name: sample-app
namespace: my-namespace
spec:
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: sample-app
minReplicas: 1
maxReplicas: 10
metrics:
- type: Object
object:
metricName: queue_length
target:
apiVersion: extensions/v1beta1
kind: Deployment
name: sample-app
targetValue: 20
But it doesn't seem to work, maybe I have to specify - type: Object
somewhat different.
I tried to change kind
to deployments, deployments.extension, deployments.extensions etc, but I keep getting error FailedGetScale
Upd.: I figured out that namespace for HPA object and target object should be the same, so I changed it. And now I'm getting
the HPA was unable to compute the replica count: unable to get metric queue_length: Deployment on default sample-app/unable to fetch metrics from custom metrics API: the server could not find the metric queue_length for deployments.extensions sample-app
Upd2.: Figured it out: hpa was in namespace default
, while metric was exposed to my-namespace
. So, should be careful with namespaces!
Try this:
---
kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
metadata:
name: sample-app
namespace: my-namespace
spec:
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: sample-app
minReplicas: 1
maxReplicas: 10
metrics:
- type: Object
object:
target:
kind: Service
name: sample-app
metricName: queue_length
targetValue: 20