[英]HPA is unable to fetch metrics from custom metrics API
我已經設置了Prometheus適配器以能夠將Prometheus指標用作kubernetes中的自定義指標,但是在使用Object HPA自動擴展部署時遇到了問題。
在這里,我從custom-metrics api獲得的所有內容。
```
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1/ | jq .
{
"kind": "APIResourceList",
"apiVersion": "v1",
"groupVersion": "custom.metrics.k8s.io/v1beta1",
"resources": [
{
"name": "services/kong_http_status_per_second",
"singularName": "",
"namespaced": false,
"kind": "MetricValueList",
"verbs": [
"get"
]
}
]
}
```
```
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1/services/*/kong_http_status_per_second | jq .
{
"kind": "MetricValueList",
"apiVersion": "custom.metrics.k8s.io/v1beta1",
"metadata": {
"selfLink": "/apis/custom.metrics.k8s.io/v1beta1/services/%2A/kong_http_status_per_second"
},
"items": [
{
"describedObject": {
"kind": "Service",
"name": "httpbin",
"apiVersion": "/v1"
},
"metricName": "kong_http_status_per_second",
"timestamp": "2019-01-08T10:30:25Z",
"value": "339m"
},
{
"describedObject": {
"kind": "Service",
"name": "httpbin",
"apiVersion": "/v1"
},
"metricName": "kong_http_status_per_second",
"timestamp": "2019-01-08T10:30:25Z",
"value": "339m"
}
]
```
然后是我的HPA:
```
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: httpbin
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: httpbin
minReplicas: 2
maxReplicas: 10
metrics:
- type: Object
object:
metricName: kong_http_status_per_second
target:
apiVersion: v1
kind: Service
name: httpbin
targetValue: 1
```
```
kubectl describe hpa
Name: httpbin
Namespace: lgrondin
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"autoscaling/v2beta1","kind":"HorizontalPodAutoscaler","metadata":{"annotations":{},"name":"httpbin","namespace":"lgrondin"}...
CreationTimestamp: Tue, 08 Jan 2019 10:22:24 +0100
Reference: Deployment/httpbin
Metrics: ( current / target )
"kong_http_status_per_second" on Service/httpbin: <unknown> / 1
Min replicas: 2
Max replicas: 10
Deployment pods: 2 current / 2 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True SucceededGetScale the HPA controller was able to get the target's current scale
ScalingActive False FailedGetObjectMetric the HPA was unable to compute the replica count: unable to get metric kong_http_status_per_second: Service on lgrondin httpbin/unable to fetch metrics from custom metrics API: the server could not find the metric kong_http_status_per_second for services
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedGetObjectMetric 87s (x449 over 4h31m) horizontal-pod-autoscaler unable to get metric kong_http_status_per_second: Service on lgrondin httpbin/unable to fetch metrics from custom metrics API: the server could not find the metric kong_http_status_per_second for services
```
似乎我可以通過直接調用api來獲取指標,但是HPA無法檢索指標。
謝謝你的幫助。
當我遇到類似的問題時,我的問題是我嘗試擴展的部署不是產生我所依賴的指標的部署。
在我的情況下,我想縮放一個吊艙,這對我有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.