【发布时间】:2019-04-07 13:27:13
【问题描述】:
我正在尝试使用 HorizontalPodAutoscaler 扩展 Kubernetes Deployment,它通过 Stackdriver 监听自定义指标。
我有一个启用了 Stackdriver 适配器的 GKE 集群。 我能够将自定义指标类型发布到 Stackdriver,以下是它在 Stackdriver 指标资源管理器中的显示方式。
这就是我定义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。
【问题讨论】:
-
默认情况下,HPA 在 kubernetes 中使用来自
metric-server的 cpu。 K8s 不知道您使用的是什么指标。您需要像部署自定义适配器/度量服务器一样。检查参考docs.bitnami.com/kubernetes/how-to/… -
我已经启用了Stackdriver adapter(我正在使用legacy 资源模型)。请问还有什么问题吗
标签: kubernetes google-kubernetes-engine stackdriver google-cloud-stackdriver