kubernetes - 使用 Cloud Monitoring 指标自动扩缩部署
问题描述
我正在尝试根据 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
看起来自定义指标名称在应用程序和 hpa 部署配置文件(yaml)中不同。app 和 hpa 部署配置文件中的指标和应用程序名称应该相同。
在 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 文件)。
推荐阅读
- angularjs - 加载指令后调用函数
- javascript - Vue:组件中的输入表单不返回值
- gstreamer - 在 vlc 中查看 rtp vp8 流
- laravel - 发生错误时,laravel mix 编译会删除旧文件吗?
- excel - Excel Power Query - 如何在 power query 的同一个表中追加列?
- html - 图像扩展了 flex 父级的高度,但在 chrome 和 safari 中出现了奇怪的 hack
- c# - 如何从 div 标签中获取文本?
- linux - Linux 根据日期在特定日志文件中搜索特定文本
- laravel - 无法使用 laravel 创建“/home/zubair/htdocs/E-soft/cms/public/images”目录
- mysql - Django ORM加入单表