[英]How to make HPA scale a deployment based on metrics produced by another deployment
我想要實現的是創建一個Horizontal Pod Autoscaler,它能夠根據controller
pod生成的自定義指標擴展worker
pod。
我已經有普羅米修斯刮,普羅米修斯Adapater,自定義度量服務器全面運作,縮放worker
與自定義指標部署my_controller_metric
由生產worker
豆莢已經工作。
現在我的worker
pod不再生成此度量標准,但controller
確實如此。 似乎API autoscaling / v1不支持此功能。 如果需要,我可以使用autoscaling / v2beta1 API指定HPA。
這是我對此HPA的規范:
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: my-worker-hpa
namespace: work
spec:
maxReplicas: 10
minReplicas: 1
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: my-worker-deployment
metrics:
- type: Object
object:
target:
kind: Deployment
name: my-controller-deployment
metricName: my_controller_metric
targetValue: 1
當使用kubectl apply -f my-worker-hpa.yml
配置時,我收到消息:
horizontalpodautoscaler "my-worker-hpa" configured
雖然這個消息似乎沒問題,但HPA不起作用。 這個規范是否格式錯誤?
正如我所說,度量標准在自定義度量服務器中可用,帶有kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq . | grep my_controller_metric
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq . | grep my_controller_metric
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq . | grep my_controller_metric
。
這是來自HPA的錯誤消息:
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 my_controller_metric: Deployment on work my-controller-deployment/unable to fetch metrics from custom metrics API: the server could not find the metric my_controller_metric for deployments
謝謝!
在您的情況下,問題是HPA配置: spec.metrics.object.target
還應指定API版本。 在spec.metrics.object.target
下放置apiVersion: extensions/v1beta1
spec.metrics.object.target
應該修復它。
此外,還有一個關於HPA中更好的配置驗證的公開問題: https : //github.com/kubernetes/kubernetes/issues/60511
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.