kubernetes - 无法从普罗米修斯适配器检索自定义指标

标签 kubernetes monitoring prometheus kubernetes-helm

我正在尝试使用 HPA + 自定义指标扩展在我的 raspberry pi kubernetes 集群上运行的我的应用程序 pod 之一,但遇到了几个问题,尽管阅读了关于 https://github.com/DirectXMan12/k8s-prometheus-adapter 的文档和过去 2 天的故障排除,我仍然难以理解为什么会发生某些问题。

首先,我构建了一个 k8s-prometheus-adapter 的 ARM 兼容镜像,并使用 helm 安装它。我可以通过检查 pod 日志来确认它是否正常运行。

我还设置了一个将树莓派温度发送到 pushgateway 的脚本,我可以通过这个 Prometheus 查询 node_temp 进行查询,它将返回以下系列

node_temp{job="kube4"}  42
node_temp{job="kube1"}  44
node_temp{job="kube2"}  39
node_temp{job="kube3"}  40  

现在我希望能够使用上述温度值作为实验来扩展我的应用程序 pod 之一,以更好地了解它的工作原理。

下面是我的 k8s-prometheus-adapter helm values.yml 文件

image:
  repository: jaanhio/k8s-prometheus-adapter-arm
  tag: latest
logLevel: 7
prometheus:
  url: http://10.17.0.12
rules:
  default: false
  custom:
  - seriesQuery: 'etcd_object_counts'
    resources:
      template: <<.Resource>>
    name:
      as: "etcd_object"
    metricsQuery: count(etcd_object_counts)
  - seriesQuery: 'node_temp'
    resources:
      template: <<.Resource>>
    name:
      as: "node_temp"
    metricsQuery: count(node_temp)

通过 helm 安装后,我运行了 kubectl get apiservices 并且可以看到列出了 v1beta1.custom.metrics.k8s.io

然后我运行 kubectl get --raw/apis/custom.metrics.k8s.io/v1beta1 | jq 得到以下内容

{
  "kind": "APIResourceList",
  "apiVersion": "v1",
  "groupVersion": "custom.metrics.k8s.io/v1beta1",
  "resources": [
    {
      "name": "jobs.batch/node_temp",
      "singularName": "",
      "namespaced": true,
      "kind": "MetricValueList",
      "verbs": [
        "get"
      ]
    },
    {
      "name": "jobs.batch/etcd_object",
      "singularName": "",
      "namespaced": true,
      "kind": "MetricValueList",
      "verbs": [
        "get"
      ]
    },
   ]

然后我尝试使用 kubectl get --raw/apis/custom.metrics.k8s.io/v1beta1/jobs/*/node_temp 查询已注册的 node_temp 指标的值,但得到以下信息回复 服务器错误(InternalError):发生内部错误:无法列出匹配的资源

问题:

  1. 为什么 node_temp 指标与 jobs.batch 资源类型关联?

  2. 为什么我无法通过 kubectl get --raw/apis/custom.metrics.k8s.io/v1beta1/jobs/*/node_temp 检索指标值?

  3. 确定查询路径的确定方法是什么?例如 /apis/custom.metrics.k8s.io/v1beta1/jobs/*/node_temp 我有点反复试验,直到看到一些响应。我还在查询中看到其他一些带有命名空间的路径,例如 /apis/custom.metrics.k8s.io/v1beta1/namespaces/*/metrics/foo_metrics

如有任何帮助和建议,我们将不胜感激!

最佳答案

  1. Why is the node_temp metrics associated with jobs.batch resource type?

它选择附加到 prometheus 指标的标签并尝试解释它们,在这种情况下你显然有“job-kube4”

  1. Why am i not able to retrieve the value of metrics via kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1/jobs/*/node_temp?

指标是命名空间的,请参阅“namespaced:true”,因此您需要“/apis/custom.metrics.k8s.io/v1beta1/namespaces//jobs//node_temp”

  1. What is a definitive way of figuring the path of the query? e.g /apis/custom.metrics.k8s.io/v1beta1/jobs//node_temp i kinda trial and error until i got see somewhat of a response. i also see some other path with namespaces in the query e.g /apis/custom.metrics.k8s.io/v1beta1/namespaces//metrics/foo_metrics

检查 https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/custom-metrics-api.md#api-paths

关于kubernetes - 无法从普罗米修斯适配器检索自定义指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61732873/

相关文章:

prometheus - Loki Ruler 未向警报经理发送警报

kubernetes - kubedns 不能以 "Failed to list *v1.Endpoints: Unauthorized"和 "Failed to list *v1.Service: Unauthorized"开头

azure - 我可以在 Azure 环境之外使用 Azure Synapse 功能吗?

java - 如何监控 Java 中特定接口(interface)的网络使用情况?

jakarta-ee - 有哪些工具可用于测量企业基于 Web 的系统的 "health"?

kubernetes - 如何从 istio-envoy 容器中抓取数据

prometheus - 是否可以通过 prometheus 获取准确的每分钟请求指标

kubernetes - CommonAnnotations 不适用于 AlertManager

kubernetes - 如何正确设置--kubelet-certificate-authority apiserver参数?

java - EJB 应用程序关闭钩子(Hook)