S
S
SSSSTTTTAAAASSSS2021-10-15 18:24:50
go
SSSSTTTTAAAASSSS, 2021-10-15 18:24:50

Question on kubernetes and prometheus: setup?

Good afternoon.
I'm trying to run prometheus monitoring via kubernetes.
At the moment everything works through docker.
Here is the docker-compose file

version: "3.1"

services:
  http:
    container_name: "http_pr"
    build:
      context: "./"
      dockerfile: "./docker/http.Dockerfile"
    ports:
      - "8085:8085"
#    links:
#      - "grpc:grpc"
    environment:
      PORT_HTTP: ":8085"
      GRPC: "grpc:9000"

  grpc:
    container_name: "grpc"
    build:
      context: "./"
      dockerfile: "./docker/grpc.Dockerfile"
    ports:
      - "9000:9000"
    environment:
      TCP_PORT: ":9000"
      DB_TYPE: "inmemory"

  prometheus:
    image: prom/prometheus:latest
    volumes:
      - ./prometheus:/etc/prometheus/
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
    ports:
      - 9090:9090
    depends_on:
      - http

  grafana:
    image: grafana/grafana:latest
    ports:
      - 3000:3000
    depends_on:
      - prometheus

and prometheus config file:
global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.
  evaluation_interval: 15s # By default, scrape targets every 15 seconds.

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
  - job_name: myCounters
    metrics_path: /posts/metrics
    static_configs:
      - targets:
          - http:8085

As far as I found on the Internet, there is no such thing as the equivalent of depends_on in kubernetes, and as an option, initContainer was offered a lot. I couldn't get started with this init.
Then I read a lot about the whole setting through namespace, cluster, etc., but as far as I understand, this is the setting of the global prometheus-a, which will monitor all the pods at once.
Who can tell me if I need to purely monitor only one node with several containers, do I need to follow this path with namespaces and other files, or can I get by with deployment and service alone?
At the moment the files are:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-deployment
  labels:
    app: prometheus
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      labels:
        app: prometheus
    spec:
      containers:
        - name: prometheus
          image: prom/prometheus
          args:
            - '--config.file=/etc/prometheus/prometheus.yml'
            - '--storage.tsdb.path=/prometheus'
#          volumeMounts:
#            - name: config-volume
#              mountPath: ./prometheus:/etc/prometheus/
          ports:
            - containerPort: 9090
#      volumes:
#        - name: config-volume

Something didn’t work out for me with volumes, while I
also committed the service:
apiVersion: v1
kind: Service
metadata:
  name: prometheus-service
spec:
  selector:
    app: prometheus
  ports:
    - protocol: TCP
      port: 9090

But in this version, I have doubts that I somehow incorrectly connect the prometheus config file, which I have configured to listen to the http service. Because the /metrics endpoint itself works for me through the http service and takes metrics, but the web interface does not see anything. It seems like I saw the option to make it a separate file and apply it, but I'm not sure if it is necessary in my case.
When forwarding the port on this service, it does not see my http service, from which it must take metrics.
Thanks in advance for any answer.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question