---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: blackbox-exporter
  labels:
    app: blackbox-exporter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: blackbox-exporter
  template:
    metadata:
      labels:
        app: blackbox-exporter
    spec:
      # The icmp prober tries an unprivileged ping socket first; this range permits it.
      securityContext:
        sysctls:
          - name: net.ipv4.ping_group_range
            value: '0 2147483647'
      containers:
        - name: blackbox-exporter
          image: prom/blackbox-exporter:latest
          args:
            - '--config.file=/etc/blackbox_exporter/blackbox.yml'
          ports:
            - containerPort: 9115
              name: http
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
                - ALL
              # Raw-socket fallback when the ping socket is refused. Without either,
              # every icmp probe fails and reads as the target being down.
              add:
                - NET_RAW
          volumeMounts:
            - name: blackbox-exporter-config
              mountPath: /etc/blackbox_exporter/
          readinessProbe:
            httpGet:
              path: /-/healthy
              port: 9115
            initialDelaySeconds: 5
            periodSeconds: 15
          livenessProbe:
            httpGet:
              path: /-/healthy
              port: 9115
            initialDelaySeconds: 15
            periodSeconds: 20
          resources:
            requests:
              memory: '32Mi'
              cpu: '25m'
      volumes:
        - name: blackbox-exporter-config
          configMap:
            name: blackbox-exporter-config

---
apiVersion: v1
kind: Service
metadata:
  name: blackbox-exporter
  labels:
    app: blackbox-exporter
spec:
  ports:
    - port: 9115
      targetPort: 9115
      protocol: TCP
      name: http
  selector:
    app: blackbox-exporter
  type: ClusterIP
