---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: alertmanager
  labels:
    app: alertmanager
spec:
  replicas: 1
  selector:
    matchLabels:
      app: alertmanager
  template:
    metadata:
      labels:
        app: alertmanager
    spec:
      containers:
        - name: alertmanager
          image: prom/alertmanager:latest
          args:
            - '--config.file=/etc/alertmanager/alertmanager.yml'
            - '--storage.path=/alertmanager'
          ports:
            - containerPort: 9093
              name: web
          volumeMounts:
            - name: alertmanager-config
              mountPath: /etc/alertmanager/
            # The bearer token Alertmanager presents to the event dispatcher,
            # written by the monitor CLI before this workload is applied. Marked
            # optional so a missing Secret surfaces as a config-load error naming
            # the file, rather than a pod stuck in ContainerCreating.
            - name: alertmanager-webhook
              mountPath: /etc/alertmanager/secret/
              readOnly: true
            - name: alertmanager-data
              mountPath: /alertmanager
          readinessProbe:
            httpGet:
              path: /-/ready
              port: 9093
            initialDelaySeconds: 10
            periodSeconds: 15
          livenessProbe:
            httpGet:
              path: /-/healthy
              port: 9093
            initialDelaySeconds: 30
            periodSeconds: 20
          resources:
            requests:
              memory: '64Mi'
              cpu: '50m'
      volumes:
        - name: alertmanager-config
          configMap:
            name: alertmanager-config
        - name: alertmanager-webhook
          secret:
            secretName: alertmanager-webhook
            optional: true
        - name: alertmanager-data
          emptyDir: {}

---
apiVersion: v1
kind: Service
metadata:
  name: alertmanager
  labels:
    app: alertmanager
spec:
  ports:
    - port: 9093
      targetPort: 9093
      protocol: TCP
      name: web
  selector:
    app: alertmanager
  type: ClusterIP
