apiVersion: apps/v1
kind: Deployment
metadata:
  name: blackbox-server
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      # Used to match pre-existing pods that may be affected during updates.
      run: blackbox-server
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  # Pod template.
  template:
    metadata:
      labels:
        # Note: run=blackbox-server should match a service config with a
        # public IP and port so that it is publically accessible.
        run: blackbox-server
      annotations:
        # Tell prometheus service discovery to scrape the blackbox container.
        prometheus.io/scrape: 'true'
    spec:
      # Schedule blackbox pods on separate nodes. Precisely, we declare an
      # anti-affinity spec keyed on the node hostnames, and selecting pods using
      # the run=blackbox-server label.
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                - key: run
                  operator: In
                  values:
                    - blackbox-server
              topologyKey: kubernetes.io/hostname
      # Place the pod into the Guaranteed QoS by setting equal resource
      # requests and limits for *all* containers in the pod.
      # For more background, see:
      # https://github.com/kubernetes/community/blob/master/contributors/design-proposals/resource-qos.md
      containers:
      # Check https://hub.docker.com/r/prom/blackbox-exporter/tags/ for the current
      # stable version.
      - image: prom/blackbox-exporter:v0.16.0
        # Note: the container name appears to be ignored and the actual pod name
        # is derived from the Deployment.metadata.name. However, removing this
        # value results in a configuration error.
        name: blackbox-server
        args: ["--config.file=/etc/blackbox/config.yml"]
        ports:
          - containerPort: 9115
        resources:
          # TODO: reduce resource allocation once
          # https://github.com/prometheus/blackbox_exporter/issues/270 is
          # resolved. These values are much more than what should be needed.
          requests:
            memory: "500Mi"
            cpu: "2000m"
          limits:
            memory: "500Mi"
            cpu: "2000m"
        volumeMounts:
        # /etc/blackbox/config.yml contains the M-Lab Prometheus config.
        - mountPath: /etc/blackbox
          name: blackbox-config

      # Disks created manually, can be named here explicitly using
      # gcePersistentDisk instead of the persistentVolumeClaim.
      volumes:
      - name: blackbox-config
        configMap:
          name: blackbox-config
