问题描述
我正在尝试根据 Cloudsql 实例响应时间自动扩展我的 pod。我们正在使用 cloudsql-proxy 进行安全连接。 部署了自定义指标适配器。
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
Metadata:
name: application_name
spec:
minReplicas: 1
maxReplicas: 5
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: application_name
minReplicas: 1
maxReplicas: 5
metrics:
- type: Pods
pods:
metric:
name: custom-metric-stackdriver-adapter
target:
type: AverageValue
averageValue: 20
我部署了应用程序并为此创建了 HPA,但我看到了错误。
AbletoScale True SucceededGetScale the HPA controller was able to get the target's current scale
ScalingActive False FailedGetPodsMetric the HPA was unable to compute the replica count: unable to get metric custom-metric: unable to fetch metrics from custom metrics API: the server Could not find the descriptor for metric custom.googleapis.com/custom-metric: googleapi: Error 404: Could not find descriptor for metric 'custom.googleapis.com/custom-metric'.,notFound
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedGetPodsMetric 4m22s (x10852 over 47h) horizontal-pod-autoscaler unable to get metric custom-metric: unable to fetch metrics from custom metrics API: the server Could not find the descriptor for metric custom.googleapis.com/custom-metric: googleapi: Error 404: Could not find descriptor for metric 'custom.googleapis.com/custom-metric'.,notFound
解决方法
- 请参考以下链接部署 HorizontalPodAutoscaler (HPA) 资源,以根据 Cloud Monitoring 指标扩展您的应用程序。
https://cloud.google.com/kubernetes-engine/docs/tutorials/autoscaling-metrics#custom-metric_4
-
看起来自定义指标名称在 app 和 hpa 部署配置文件 (yaml) 中有所不同。应用和 hpa 部署配置文件中的指标和应用名称应相同。
-
在 hpa 部署 yaml 文件中,
一个。将 custom-metric-stackdriver-adapter 替换为 custom-metric(或更改 应用部署 yaml 中自定义度量堆栈驱动程序适配器的度量名称 文件)。
B.在元数据的应用程序名称旁边添加“命名空间:默认”。另外 确保您在应用程序部署配置中添加命名空间 文件。
c.删除重复的第 6 行和第 7 行(minReplicas: 1,maxReplicas: 5)。
d。转到 Cloud Console->Kubernetes Engine->工作负载。删除由应用部署 yaml 和 adapter_new_resource_model.yaml 文件创建的工作负载(application-name 和 custom-metrics-stackdriver-adapter)。
e.现在将配置应用到资源模型、应用程序和 hpa(yaml 文件)。