【问题标题】:Can I use metrics from one application to automatically scale a different one?我可以使用来自一个应用程序的指标来自动扩展另一个应用程序吗?
【发布时间】:2018-10-08 10:14:09
【问题描述】:

我目前在我的 kubernetes 集群中运行一个服务,它将我的指标导出到监控我的集群和服务的 prometheus。

我想使用此服务中的指标来根据这些指标自动扩展 (hpa) 第二个服务。

这可能吗?

提前致谢!

【问题讨论】:

    标签: kubernetes prometheus horizontal-scaling


    【解决方案1】:

    我已经成功了!

    您可以在一个参数中选择规模目标,然后在指标部分选择不同服务的目标。

    示例 yaml

    kind: HorizontalPodAutoscaler
    apiVersion: autoscaling/v2beta1
    metadata:
      name: my-app-hpa
    spec:
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: my-app
      minReplicas: 1
      maxReplicas: 5
      metrics:
      - type: Object
        object:
          target:
            kind: Service
            name: app-that-generates-metrics
          metricName: my-metric
          targetValue: 10
    

    【讨论】:

    • 指标是cpu/memorynetwork 还是来自app-that-generates-metrics 的自定义总值?
    • 来自应用的自定义值
    【解决方案2】:

    我从未测试过你想做什么,但这里有一个关于如何使用自定义指标扩展 pod 的教程:https://docs.bitnami.com/kubernetes/how-to/configure-autoscaling-custom-metrics/

    您可能需要做一些调整才能使用 pod 中的指标来扩展另一个指标,但我希望它会有所帮助。

    【讨论】:

    • 我试试看hpa yaml是否可以引用不同的服务
    • 由于教程中的某种原因,您发送的 hpa 无法识别当前 http 请求的数量,即使 prometheus 正在收集它
    • 这与您使用不同的 pod 有什么关系吗?所以该指标不适用于您的 hpa?
    【解决方案3】:

    要开始使用custom HPA,您需要在集群上安装一些东西:

    1. 启用Kubernetes Aggregator Layer
    2. 开始使用 metrics-server(而不是 heapster);

    【讨论】:

      猜你喜欢
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      • 2019-07-10
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      • 2011-03-27
      • 2021-04-08
      相关资源
      最近更新 更多