PodMonitor

O que é o PodMonitor?

O PodMonitor é um recurso do Prometheus Operator que permite que você configure o Prometheus para monitorar um pod. Ele é um Custom Resource Definition (CRD) que pode ser criado no Kubernetes.

Criando nosso Pod e o PodMonitor

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx-pod
spec:
  containers:
    - name: nginx
      image: nginx
      ports:
        - containerPort: 80
          name: http
      volumeMounts:
        - name: nginx-config
          mountPath: /etc/nginx/conf.d/default.conf
          subPath: nginx.conf
    - name: nginx-exporter
      image: "nginx/nginx-prometheus-exporter:0.11.0"
      args:
        - "-nginx.scrape-uri=http://localhost/metrics"
      resources:
        requests:
          cpu: 0.1
          memory: 64Mi
        limits:
          cpu: 0.3
          memory: 128Mi
      ports:
        - containerPort: 9113
          name: metrics
  volumes:
    - configMap:
        defaultMode: 420
        name: nginx-config
      name: nginx-config
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: nginx-pod-monitor
  labels:
    app: nginx
spec:
  namespaceSelector:
    matchNames:
      - default
  selector:
    matchLabels:
      app: nginx-pod
  podMetricsEndpoints:
  - port: metrics
    interval: 10s
    path: /metrics
    targetPort: 9113