【发布时间】:2019-03-14 14:27:18
【问题描述】:
我配置了一个自定义指标。
当我跑步时:
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/my-namespace/deployments.extensions/sample-app/queue_length" | jq
我明白了:
...
"items": [
{
"describedObject": {
"kind": "Deployment",
"namespace": "my-namespace",
"name": "sample-app",
"apiVersion": "extensions/v1beta1"
},
"metricName": "queue_length",
"timestamp": "2018-10-09T18:14:15Z",
"value": "30"
}
]
...
所以我想用这个指标来扩展我的部署:
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
但这似乎不起作用,也许我必须指定- type: Object有点不同。
我尝试将kind 更改为部署、部署.扩展、部署.扩展等,但我不断收到错误FailedGetScale
更新:我发现 HPA 对象和目标对象的命名空间应该相同,所以我更改了它。现在我得到了
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.: 弄清楚了:hpa 在命名空间 default 中,而 metric 暴露在 my-namespace 中。所以,应该小心命名空间!
【问题讨论】: