1

我正在尝试根据 CloudSQL 实例响应时间自动扩展我的 pod。我们正在使用 cloudsql-proxy 进行安全连接。部署了自定义指标适配器。

https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/production/adapter_new_resource_model.yaml

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
4

1 回答 1

0
  1. 请参阅下面的链接以部署 Horizo​​ntalPodAutoscaler (HPA) 资源,以根据 Cloud Monitoring 指标扩展您的应用程序。

https://cloud.google.com/kubernetes-engine/docs/tutorials/autoscaling-metrics#custom-metric_4

  1. 看起来自定义指标名称在应用程序和 hpa 部署配置文件(yaml)中不同。app 和 hpa 部署配置文件中的指标和应用程序名称应该相同。

  2. 在 hpa 部署 yaml 文件中,

    一个。将 custom-metric-stackdriver-adapter 替换为 custom-metric(或在应用部署 yaml 文件中将指标名称更改为 custom-metric-stackdriver-adapter)。

    湾。在元数据的应用程序名称旁边添加“命名空间:默认”。同时确保在应用程序部署配置文件中添加命名空间。

    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 文件)。

于 2021-05-21T06:51:18.337 回答