简体   繁体   English

prometheus 不会从部署在 kubernetes 上的应用程序中抓取指标

[英]prometheus is not scraping the metrics from the app deployed on kubernetes

I have added endpoint /metrics in my app and this is the config file i have written for prometheus我在我的应用程序中添加了端点/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

and below is the deployment file下面是部署文件

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.

and this is the deployment file for the app这是应用程序的部署文件

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

I have created the service of prometheus and goserver on port 32514 and 32520 respectively of the type NodePort.我已经分别在 NodePort 类型的端口 32514 和 32520 上创建了 prometheus 和 goserver 的服务。 This is working fine with the minikube and scrapes the metrics from my app but not working with the kubeadm setup in virtual box (multinode cluster).这是工作的罚款与minikube和我的应用程序的指标,但不与虚框(多节点集群)的kubeadm设置工作。 What changes i have to make in order to get the metrics on kubernetes.为了获得 kubernetes 的指标,我必须进行哪些更改。 I tried to make few changes in rbac-setup.yaml and prometheus-kubernetes.yaml also but it is not working.我也尝试对rbac-setup.yamlprometheus-kubernetes.yaml进行一些更改,但它不起作用。

I am accessing the browser by ssh -NL 1234:localhost:32514 from outside the cluster,because vagrant box does not have ubuntu desktop ui.我正在通过 ssh -NL 1234:localhost:32514 从集群外部访问浏览器,因为 vagrant box 没有 ubuntu 桌面 ui。

i found the issue,actually the issue was related to rbac.我发现了这个问题,实际上这个问题与 rbac 有关。 I didn't added the serviceAccountName in deployment file.我没有在部署文件中添加 serviceAccountName。 Now it is working fine with the new change.现在它在新的变化下工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kubernetes 中的示例容器化应用程序无法在 Prometheus 中显示为用于抓取指标的目标 - A sample containerized application in Kubernetes unable to be shown as targets in Prometheus for scraping metrics Prometheus 配置以忽略对 Kubernetes 中特定命名空间的指标的抓取 - Prometheus config to ignore scraping of metrics for a specific namespace in Kubernetes HPA无法从Kubernetes中的Prometheus获取指标 - HPA not able to fetch metrics from Prometheus in Kubernetes Kubernetes / Prometheus指标不匹配 - Kubernetes / Prometheus Metrics Mismatch Prometheus - Kubernetes 集群指标 - Prometheus - Kubernetes cluster metrics 使用 Django 和 Kubernetes 部署 prometheus,如何让它抓取 Django 应用程序? - Deployed prometheus with Django and Kubernetes, how to make it scrape the Django app? 在 prometheus 中排除 Kubernetes 指标监控 - Exclude Kubernetes Metrics monitoring in prometheus kubernetes 指标的 Prometheus 适配器配置 - Prometheus Adapter configuration for kubernetes metrics Prometheus + Kubernetes指标来自错误的抓取工作 - Prometheus + Kubernetes metrics coming from wrong scrape job 在 Grafana 中显示来自 Prometheus 最后抓取的 Kubernetes Pod 的指标 - Show metrics in Grafana from the Kubernetes Pod that was scraped last by Prometheus
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM