gpt4 book ai didi

kubernetes - Kubernetes HPA无法从Stackdriver检测到成功发布的自定义指标

转载 作者:行者123 更新时间:2023-12-02 11:37:14 24 4
gpt4 key购买 nike

我正在尝试使用Deployment扩展Kubernetes的HorizontalPodAutoscaler,它通过Stackdriver监听自定义指标。

我有一个启用了Stackdriver适配器的GKE群集。
我可以将自定义指标类型发布到Stackdriver,以下是它在Stackdriver Metric Explorer中的显示方式。

enter image description here

enter image description here

这就是我定义HPA的方式:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa
spec:
minReplicas: 1
maxReplicas: 10
metrics:
- type: External
external:
metricName: custom.googleapis.com|worker_pod_metrics|baz
targetValue: 400
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: test-app-group-1-1

成功创建 example-hpa后,执行 kubectl get hpa example-hpa,始终将 TARGETS显示为 <unknown>,并且永远不会从自定义指标中检测到该值。
NAME          REFERENCE                       TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
example-hpa Deployment/test-app-group-1-1 <unknown>/400 1 10 1 18m

我正在使用在本地运行的Java客户端发布我的自定义指标。
我已经给了适当的资源标签,如 here所述(硬编码-这样它就可以在本地环境中正常运行)。我遵循 this document创建Java客户端。

private static MonitoredResource prepareMonitoredResourceDescriptor() {
Map<String, String> resourceLabels = new HashMap<>();
resourceLabels.put("project_id", "<<<my-project-id>>>);
resourceLabels.put("pod_id", "<my pod UID>");
resourceLabels.put("container_name", "");
resourceLabels.put("zone", "asia-southeast1-b");
resourceLabels.put("cluster_name", "my-cluster");
resourceLabels.put("namespace_id", "mynamespace");
resourceLabels.put("instance_id", "");

return MonitoredResource.newBuilder()
.setType("gke_container")
.putAllLabels(resourceLabels)
.build();
}

请问上述步骤我做错了什么?预先感谢您提供的任何答案!

编辑[已解决] :
我认为我有一些配置错误,因为 kubectl describe hpa [NAME] --v=9向我显示了一些 403状态代码,以及我使用的是 type: External而不是 type: Pods(感谢 MWZ的回答,指出了这个错误)。

我设法通过创建一个新项目,一个新服务帐户和一个新GKE群集(基本上是从头开始的所有内容)来修复它。然后,按照 this document的说明,如下更改了yaml文件。
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: test-app-group-1-1
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1beta1
kind: Deployment
name: test-app-group-1-1
minReplicas: 1
maxReplicas: 5
metrics:
- type: Pods # Earlier this was type: External
pods: # Earlier this was external:
metricName: baz # metricName: custom.googleapis.com|worker_pod_metrics|baz
targetAverageValue: 20

我现在要导出为 custom.googleapis.com/baz,而不是 custom.googleapis.com/worker_pod_metrics/baz。另外,现在我在yaml中为我的HPA明确指定 namespace

最佳答案

由于您可以在Stackdriver GUI中看到自定义指标,因此我猜测指标已正确导出。我相信基于Autoscaling Deployments with Custom Metrics,HPA使用错误的度量标准来扩展部署。

请尝试使用此YAML:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa
spec:
minReplicas: 1
maxReplicas: 10
metrics:
- type: Pods
pods:
metricName: baz
targetAverageValue: 400
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: test-app-group-1-1

请记住:

The HPA uses the metrics to compute an average and compare it to the target average value. In the application-to-Stackdriver export example, a Deployment contains Pods that export metric. The following manifest file describes a HorizontalPodAutoscaler object that scales a Deployment based on the target average value for the metric.



page above上描述的故障排除步骤也可能有用。

旁注
由于上述HPA使用beta API autoscaling/v2beta1,因此在运行 kubectl describe hpa [DEPLOYMENT_NAME]时出现错误。我运行 kubectl describe hpa [DEPLOYMENT_NAME] --v=9并在JSON中得到响应。

关于kubernetes - Kubernetes HPA无法从Stackdriver检测到成功发布的自定义指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55559504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com