首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kubernetes HPA没有使用istio上的prometheus适配器进行自定义度量

Kubernetes HPA没有使用istio上的prometheus适配器进行自定义度量
EN

Stack Overflow用户
提问于 2021-01-07 06:28:06
回答 1查看 1.2K关注 0票数 1

我有两个在istio中运行相同服务的v1和v2的部署。我已经建立了一个自定义度量‘istio-总计-请求’通过prometheus适配器收集。

我已经设置了一个HPA来扩展v2部署,并且在发送请求时可以看到目标值的增加,但是没有发生的是HPA没有缩放豆荚/副本的数量。

我在minikube v1.13.1上运行kubernetes v1.19,不明白它为什么不扩展。

代码语言:javascript
复制
prometheus:
  url: http://prometheus.istio-system.svc.cluster.local
rules:
  default: false
  custom:
# this rule matches cumulative cAdvisor metrics measured in seconds
  - seriesQuery: 'istio_requests_total{kubernetes_namespace!="",kubernetes_pod_name!=""}'
    seriesFilters: []      
    resources:
      # template: <<.Resource>>
      # skip specifying generic resource<->label mappings, and just
      # attach only pod and namespace resources by mapping label names to group-resources
      overrides:
        kubernetes_namespace: {resource: "namespace"}
        kubernetes_pod_name: {resource: "pod"}
    # specify that the `container_` and `_seconds_total` suffixes should be removed.
    # this also introduces an implicit filter on metric family names
    name:
      # we use the value of the capture group implicitly as the API name
      # we could also explicitly write `as: "$1"`
      matches: "^(.*)_total"
      as: "${1}_per_second"
      # matches: ""
      # as: ""
    # specify how to construct a query to fetch samples for a given series
    # This is a Go template where the `.Series` and `.LabelMatchers` string values
    # are available, and the delimiters are `<<` and `>>` to avoid conflicts with
    # the prometheus query language
    metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>)"

HPA YAML

代码语言:javascript
复制
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: translate-deployment-v2-hpa
spec:
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Pods
    pods:
      metric:
        name: istio_requests_per_second
        # selector: {matchLabels: {destination_version: 0.0.2}}
      target:
        type: AverageValue
        averageValue: 10
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: translate-deployment-v2      

请参阅HPA拉动和测量度量,但没有缩放,它下面的窗口显示prometheus适配器是否成功地被查询到度量。

HPA描述

最后一个我不清楚的项目是,在上面的hpa定义中,选择器的目的是什么?是从prometheus查询的数据范围中选择特定的值吗?

例如,我知道我查询的字段默认是由公使输出的,如下所示:

代码语言:javascript
复制
istio_requests_total{app="istio-ingressgateway",chart="gateways",connection_security_policy="unknown",destination_app="translate-pod",destination_canonical_revision="0.0.1",destination_canonical_service="translate-pod",destination_principal="spiffe://cluster.local/ns/default/sa/default",destination_service="translate-service.default.svc.cluster.local",destination_service_name="translate-service",destination_service_namespace="default",destination_version="0.0.1",destination_workload="translate-deployment",destination_workload_namespace="default",heritage="Tiller",install_operator_istio_io_owning_resource="unknown",instance="172.17.0.5:15020",istio="ingressgateway",istio_io_rev="default",job="kubernetes-pods",kubernetes_namespace="istio-system",kubernetes_pod_name="istio-ingressgateway-6cfd75fc57-flmhp",operator_istio_io_component="IngressGateways",pod_template_hash="6cfd75fc57",release="istio",reporter="source",request_protocol="http",response_code="200",response_flags="-",service_istio_io_canonical_name="istio-ingressgateway",service_istio_io_canonical_revision="latest",source_app="istio-ingressgateway",source_canonical_revision="latest",source_canonical_service="istio-ingressgateway",source_principal="spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account",source_version="unknown",source_workload="istio-ingressgateway",source_workload_namespace="istio-system"}

选择器是否允许您进一步过滤系列数据,如果不是,目的是什么以及如何使用它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-07 09:25:45

根据您的屏幕截图,HPA的工作与预期一样,因为您的度量值低于阈值。如果该值未超过阈值,则HPA将不会触发缩放。相反,在你的情况下,它可能会触发缩小的规模。

您现在使用的度量是istio_requests_per_second。它是由每秒的总请求计算的。第一个屏幕截图显示平均值是200m,它将是0.2。您的阈值是10,所以在这种情况下,HPA绝对不会增加。

对于选择器,它使您能够在指标下选择目标标签。例如,如果您只想针对GET方法缩放实例。在这种情况下,您可以定义与GET方法标签匹配的选择器。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65607610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档