我尝试在 GKE 中使用基于外部指标的 HPA,但它给出了错误 -
horizontal-pod-autoscaler unable to get external metric default/custom.googleapis.com|rabbitmq_queue_messages_ready/nil: unable to fetch metrics from external metrics API: the server is currently unable to handle the request (get custom.googleapis.com|rabbitmq_queue_messages_ready.external.metrics.k8s.io
我在 k8 集群中设置了一个外部指标,用于将数据发送到 google stackdriver。该指标包含有关rabbitmq中消息数量的信息,该队列位于集群外。根据队列长度,我正在尝试自动缩放我的 Pod。 现在我可以将数据推送到 stackdriver,并可以在 Metric Explorer 中查看指标。但是当我尝试在 HPA 中使用它时,它给出了错误。
HPA-
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: exp-anno-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1beta1
kind: Deployment
name: exp-anno
minReplicas: 2
maxReplicas: 6
metrics:
- type: External
external:
metricName: "custom.googleapis.com|rabbitmq_queue_messages_ready"
targetValue: 10
https://github.com/GoogleCloudPlatform/k8s-stackdriver/issues/315
太晚了,但解决方案在这个链接中。在部署规范中设置 hostNetwork: true 。