【问题标题】:prometheus is not scraping the metrics from the app deployed on kubernetesprometheus 不会从部署在 kubernetes 上的应用程序中抓取指标
【发布时间】:2017-09-11 10:51:42
【问题描述】:

我在我的应用中添加了端点/metrics 并且 这是我为prometheus编写的配置文件

kind: ConfigMap
metadata:
  name: prometheus-config
apiVersion: v1
data:
  prometheus.yml: |-
    global:
      scrape_interval: 5s
      evaluation_interval: 5s
    scrape_configs:
    - job_name: 'goserver'
      scheme: http
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      kubernetes_sd_configs:
      - api_server: https://kubernets.default.svc
        role: pod
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app]
        regex: goserver
        action: keep
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: k8s_pod
        action: replace

下面是部署文件

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: prometheus-deployment
spec:
  replicas: 1
  template:
  metadata:
    labels:
      app: prometheus-server
  spec:
    containers:
    - name: prometheus
      image: prom/prometheus:latest
      args:
        - "-config.file=/etc/prometheus/conf/prometheus.yml"
        # Metrics are stored in an emptyDir volume which
        # exists as long as the Pod is running on that Node.
        # The data in an emptyDir volume is safe across container crashes.
        - "-storage.local.path=/prometheus"
      ports:
        - containerPort: 9090
      volumeMounts:
        - name: prometheus-server-volume
          mountPath: /etc/prometheus/conf
        - name: prometheus-storage-volume
          mountPath: /prometheus
  volumes:
    - name: prometheus-server-volume
      configMap:
        name: prometheus-config
    - name: prometheus-storage-volume
      emptyDir: {} # containers in the Pod can all read and write the same files here.

这是应用的部署文件

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: server-deployment
  namespace: default
spec:
  replicas: 1
  template:
    metadata:
      labels:
         app: goserver
    spec:
      containers:
      - name: goserver
        imagePullPolicy: Always
        image: utkarshmani1997/goserver:v1.4
        ports:
        - containerPort: 8080

我已经在 NodePort 类型的端口 32514 和 32520 上分别创建了 prometheus 和 goserver 服务。 这适用于我的应用程序中的 minikube 和 scrapes 指标,但不适用于虚拟盒(多节点集群)中的 kubeadm 设置。为了获得 kubernetes 上的指标,我必须进行哪些更改。 我也尝试对rbac-setup.yamlprometheus-kubernetes.yaml 进行一些更改,但它不起作用。

我从集群外部通过 ssh -NL 1234:localhost:32514 访问浏览器,因为 vagrant box 没有 ubuntu 桌面 ui。

【问题讨论】:

  • 你能从运行 Prometheus 的节点卷曲 go 应用 /metrics 端点吗?
  • @Gavin 是的,在进行 curl 时,它会废弃自定义指标。
  • 问题是 'goserver' pod 的状态已关闭,并给出“无法跳过 io_prometheus_client.MetricFamily 的未知线路类型 7”错误
  • 看看 - groups.google.com/forum/#!topic/prometheus-developers/…,似乎是内容格式问题 - Prometheus 期望/配置为通过 protobuf 读取,但输出格式实际上是文本。

标签: kubernetes prometheus


【解决方案1】:

我发现了这个问题,实际上这个问题与 rbac 有关。我没有在部署文件中添加 serviceAccountName。现在它可以很好地适应新的变化。

【讨论】:

    猜你喜欢
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 2019-01-30
    • 2022-01-27
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多