apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: prometheus
  namespace: kube-system
  labels:
    k8s-app: prometheus
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
    version: v2.19.2
spec:
  serviceName: "prometheus"
  replicas: 1
  podManagementPolicy: "Parallel"
  updateStrategy:
   type: "RollingUpdate"
  selector:
    matchLabels:
      k8s-app: prometheus
  template:
    metadata:
      labels:
        k8s-app: prometheus
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
    spec:
      priorityClassName: system-cluster-critical
      serviceAccountName: prometheus
      initContainers:
      - name: init-chown-data
        image: nat-harbor.daocloud.io/os/alpine:3.11
        imagePullPolicy: IfNotPresent
        command: ["chown", "-R", "65534:65534", "/data"]
        volumeMounts:
        - name: prometheus-data
          mountPath: /data
      containers:
      - name: cm-reload-config
        image: bitnami/configmap-reload:0.3.0
        imagePullPolicy: IfNotPresent
        args:
        - --volume-dir=/etc/config
        - --webhook-url=http://localhost:9090/-/reload
        volumeMounts:
        - name: config-volume
          mountPath: /etc/config
          readOnly: true
        resources:
          limits:
            cpu: 100m
            memory: 128Mi
          requests:
            cpu: 100m
            memory: 128Mi
      - name: cm-reload-alert
        image: bitnami/configmap-reload:0.3.0
        imagePullPolicy: IfNotPresent
        args:
        - --volume-dir=/etc/alerts
        - --webhook-url=http://localhost:9090/-/reload
        volumeMounts:
        - name: alert-rules
          mountPath: /etc/alerts
          readOnly: true
        resources:
          limits:
            cpu: 100m
            memory: 128Mi
          requests:
            cpu: 100m
            memory: 128Mi
      - name: prometheus-server
        image: prom/prometheus:v2.19.2
        imagePullPolicy: IfNotPresent
        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
        resources:
          limits:
            cpu: "4"
            memory: 8Gi
          requests:
            cpu: "4"
            memory: 8Gi
        volumeMounts:
        - name: config-volume
          mountPath: /etc/config
        - name: alert-rules
          mountPath: /etc/alerts
        - name: prometheus-data
          mountPath: /data
          subPath: ""
      terminationGracePeriodSeconds: 60
      volumes:
      - name: config-volume
        configMap:
          name: prometheus-config
      - name: alert-rules
        configMap:
          name: prometheus-alert-rules
  volumeClaimTemplates:
  - metadata:
      name: prometheus-data
    spec:
      storageClassName: data
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 50Gi