############################################
# Prometheus exporter for K8s that serves
# metrics from a plain text file
############################################
apiVersion: apps/v1
kind: Deployment
metadata:
  name: from-file-prometheus-exporter
  labels:
    app: from-file-prometheus-exporter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: from-file-prometheus-exporter
  template:
    metadata:
      labels:
        app: from-file-prometheus-exporter
        prometheus.io/scrape: "true"
    spec:
      containers:
        - name: from-file-prometheus-exporter
          image: python:alpine3.9
          env:
            - name: METRICS_FILE_URL
              value: "<ADD_YOUR_FILE_URL_HERE>" # You can use private gist url.
          ports:
            - name: metrics
              containerPort: 8080
          command: ["/bin/sh","-c"]
          # The reason of using a URL instead of a config map is that the latest has a limitation of up to 1MB
          args: ["wget $METRICS_FILE_URL -O /etc/from-file-prometheus-exporter/metrics; python -m http.server -b 0.0.0.0 -d /etc/from-file-prometheus-exporter/ 8080"]
          volumeMounts:
            - mountPath: /etc/from-file-prometheus-exporter/
              name: metrics-dir
          readinessProbe:
            httpGet:
              path: /
              port: metrics
            initialDelaySeconds: 10
            periodSeconds: 5
      volumes:
        - name: metrics-dir
          emptyDir: {}
