apiVersion: apps/v1
kind: Deployment
metadata:
  name: alertmanager-server
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      # Used to match pre-existing pods that may be affected during updates.
      run: alertmanager-server
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  # Pod template.
  template:
    metadata:
      labels:
        # Note: run=alertmanager-server should match a service config with a
        # public IP and port so that it is publically accessible.
        run: alertmanager-server
    spec:
      # 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/alertmanager/tags/ for the current
      # stable version.
      - image: prom/alertmanager:v0.19.0
        name: alertmanager-server
        env:
        - name: ALERTMANAGER_EXTERNAL_URL
          # A public domain name used to access alertmanager from a browser.
          # The external url is used in alert URLs generated by alertmanager.
          valueFrom:
            configMapKeyRef:
              name: alertmanager-env
              key: external-url
        args: ["--config.file=/etc/alertmanager/config.yml",
               "--web.external-url=$(ALERTMANAGER_EXTERNAL_URL)",
               "--storage.path=/alertmanager"]
        ports:
          - containerPort: 9093
        resources:
          requests:
            memory: "400Mi"
            cpu: "200m"
          limits:
            memory: "400Mi"
            cpu: "200m"
        volumeMounts:
        # /alertmanager stores alert state, like acks, silences, etc.
        - mountPath: /alertmanager
          name: alertmanager-storage
          subPath: alertmanager-data
        # /etc/alertmanager/config.yml contains the M-Lab alertmanager config.
        - mountPath: /etc/alertmanager
          name: alertmanager-config

      # Check https://hub.docker.com/r/jimmidyson/configmap-reload/tags/ for the current
      # stable version.
      - image: jimmidyson/configmap-reload:v0.2.2
        name: configmap-reload
        args: ["-webhook-url", "$(ALERTMGR_RELOAD_URL)", "-volume-dir", "/alertmanager-config"]
        env:
        - name: ALERTMGR_RELOAD_URL
          valueFrom:
            configMapKeyRef:
              name: configmap-reload-urls
              key: alertmanager_reload_url
        resources:
          requests:
            memory: "400Mi"
            cpu: "200m"
          limits:
            memory: "400Mi"
            cpu: "200m"
        volumeMounts:
        # Mount the prometheus config volume so we can watch it for changes.
        - mountPath: /alertmanager-config
          name: alertmanager-config

      # Disks created manually, can be named here explicitly using
      # gcePersistentDisk instead of the persistentVolumeClaim.
      volumes:
      - name: alertmanager-storage
        persistentVolumeClaim:
          claimName: auto-alertmanager-disk0
      - name: alertmanager-config
        configMap:
          name: alertmanager-config
