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

我正在尝试使用 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

https://stackoverflow.com/questions/61732873/

相关文章:

google-app-engine - 如何使用 Google Cloud Tasks 扩展拉取队列

python - 包含 json 格式列的 Dask 数据框

spring-boot - 如何将Keycloak注册到Spring Eureka Server

python - 你如何使用 python-rtmidi 获取 midi 事件

angular - 如何从变量在 [innerHTML] 上启用 ngx-bootstrap 工具提

css - 有没有办法使用变换比例使内容自动适合父 div?

laravel - Firefox 无法与 wss ://127. 0.0.1 的服务器建立连接

java - Netbeans 中的 JUnit 5 测试

karate - 在 Karate 中通过标签并行运行功能

c# - w[警告]未找到测试结果文件 azure devops