apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: prometheus
  namespace: lens-metrics
spec:
  replicas: 1
  serviceName: prometheus
  selector:
    matchLabels:
      name: prometheus
  template:
    metadata:
      labels:
        name: prometheus
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: kubernetes.io/os
                  operator: In
                  values:
                  - linux
              - matchExpressions:
                - key: beta.kubernetes.io/os
                  operator: In
                  values:
                  - linux
      serviceAccountName: prometheus
      initContainers:
        - name: chown
          image: docker.io/alpine:3.9
          command: ["chown", "-R", "65534:65534", "/var/lib/prometheus"]
          volumeMounts:
            - name: data
              mountPath: /var/lib/prometheus
      containers:
        - name: prometheus
          image: docker.io/prom/prometheus:v2.27.1
          args:
            - --web.listen-address=0.0.0.0:9090
            - --config.file=/etc/prometheus/prometheus.yaml
            - --storage.tsdb.path=/var/lib/prometheus
            - --storage.tsdb.retention.time=15d
            - --storage.tsdb.retention.size=8GB
            - --storage.tsdb.min-block-duration=2h
            - --storage.tsdb.max-block-duration=2h
          ports:
            - name: web
              containerPort: 9090
          volumeMounts:
            - name: config
              mountPath: /etc/prometheus
            - name: rules
              mountPath: /etc/prometheus/rules
            - name: data
              mountPath: /var/lib/prometheus
          readinessProbe:
            httpGet:
              path: /-/ready
              port: 9090
            initialDelaySeconds: 10
            timeoutSeconds: 10
          livenessProbe:
            httpGet:
              path: /-/healthy
              port: 9090
            initialDelaySeconds: 10
            timeoutSeconds: 10
          resources:
            requests:
              cpu: 100m
              memory: 512Mi
      terminationGracePeriodSeconds: 30
      volumes:
        - name: config
          configMap:
            name: prometheus-config
        - name: rules
          configMap:
            name: prometheus-rules
        - name: data
          persistentVolumeClaim: 
            claimName: prometheus
