apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: prometheus
  namespace: monitoring
  labels:
    app: prometheus
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
    version: v2.2.1
spec:
  serviceName: "prometheus"
  replicas: 1
  podManagementPolicy: "Parallel"
  updateStrategy:
    type: "RollingUpdate"
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      labels:
        app: prometheus
    spec:
      serviceAccountName: prometheus
      initContainers:
        - name: init-chown-data
          image: busybox:latest
          imagePullPolicy: Always
          command: ["chown", "-R", "65534:65534", "/data"]
          volumeMounts:
            - name: prometheus-persistent-storage
              mountPath: /data
              subPath: ""
      containers:
        - name: prometheus-server
          image: prom/prometheus:v2.27.0
          imagePullPolicy: Always
          args:
            - --config.file=/etc/config/prometheus.yml
            - --storage.tsdb.path=/data
            - --web.console.libraries=/etc/prometheus/console_libraries
            - --web.console.templates=/etc/prometheus/consoles
            - --web.enable-lifecycle
          ports:
            - containerPort: 9090
          readinessProbe:
            httpGet:
              path: /-/ready
              port: 9090
            initialDelaySeconds: 30
            timeoutSeconds: 30
          livenessProbe:
            httpGet:
              path: /-/healthy
              port: 9090
            initialDelaySeconds: 30
            timeoutSeconds: 30

          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
            - name: prometheus-persistent-storage
              mountPath: /data
              subPath: ""
      terminationGracePeriodSeconds: 300
      volumes:
        - name: config-volume
          configMap:
            name: prometheus-config
  volumeClaimTemplates:
    - metadata:
        name: prometheus-persistent-storage
      spec:
        storageClassName: prometheus
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: "16Gi"
