如何为类型配置自动缩放:对象
Posted
技术标签:
【中文标题】如何为类型配置自动缩放:对象【英文标题】:How to configure autoscaling for type: Object 【发布时间】: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
中。所以,应该小心命名空间!
【问题讨论】:
【参考方案1】:试试这个:
---
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
【讨论】:
试过了,但也不管用:ScalingActive False FailedGetObjectMetric the HPA was unable to compute the replica count: unable to get metric celery_production_yodlee: Service on default sample-app/unable to fetch metrics from custom metrics API: the server could not find the metric celery_production_yodlee for services.extensions
。因为我有 API 路径 namespaces/my-namespace/deployments.extensions/sample-app/queue_length
应该有 deployment
我认为
哦,糟糕。什么是回归? kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/my-namespace/services/*/queue_length" | jq .以上是关于如何为类型配置自动缩放:对象的主要内容,如果未能解决你的问题,请参考以下文章
Chart.js - 如何为随时间发生的大量数据创建自动缩放折线图
如何为 Elastic Load Balancer 配置自动超时?