apiVersion: v1
kind: Service
metadata:
  name: ping-exporter
  namespace: home-apps
  labels:
    name: ping-exporter
    app: ping-exporter
spec:
  ports:
    - port: 9427
      name: metrics-port
      targetPort: 9427
  selector:
    app: ping-exporter

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: ping-config
  namespace: home-apps
data:
  config.yml: |
    ---
    targets:
      - 8.8.8.8
      - google.com

    dns:
      refresh: 2m15s
      nameserver: 1.1.1.1

    ping:
      interval: 5s
      timeout: 3s
      history-size: 42
      payload-size: 120

    options:
      disableIPv6: true
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ping-exporter
  namespace: home-apps
spec:
  selector:
    matchLabels:
      app: ping-exporter
  replicas: 1
  template:
    metadata:
      labels:
        name: ping-exporter
        app: ping-exporter
    spec:
      volumes:
        - name: config-volume
          configMap:
            name: ping-config
      imagePullSecrets:
        - name: regcred
      containers:
        - name: ping-exporter
          image: czerwonk/ping_exporter
          ports:
            - name: metrics-port
              containerPort: 9427
          resources:
            requests:
              cpu: 25m
              memory: 64Mi
            limits:
              cpu: 50m
              memory: 128Mi
          securityContext:
            privileged: true
            # runAsGroup: 1000
            # fsGroup: 1000
            # runAsUser: 1000
          volumeMounts:
            - name: config-volume
              mountPath: /config/config.yml
              subPath: config.yml
              readOnly: true

---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: ping-exporter
  namespace: home-apps
  labels:
    app: ping-exporter
    release: prometheus # this can make the service monitor be discovered by prometheus
spec:
  selector:
    matchLabels:
      app: ping-exporter
  endpoints:
    - port: metrics-port
      targetPort: metrics-port
      interval: 5s
