apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: loki
spec:
  replicas: 1
  serviceName: loki-headless
  updateStrategy:
    type: RollingUpdate
  podManagementPolicy: OrderedReady
  selector:
    matchLabels:
      app: loki
  template:
    metadata:
      labels:
        app: loki
    spec:
      serviceAccountName: loki
      terminationGracePeriodSeconds: 4800

      securityContext:
        runAsUser: 1001
        runAsGroup: 1001
        fsGroup: 1001

      containers:
        - name: loki
          image: grafana/loki:2.2.0@sha256:2bca096f7744b7776577f701fab87079dabe9889b93ad2432e82779e5af032ef
          imagePullPolicy: IfNotPresent

          args:
            - "-config.file=/etc/loki/loki.yaml"

          ports:
            - name: http-metrics
              containerPort: 3100
              protocol: TCP

          resources:
            requests:
              cpu: 500m
              memory: 512Mi
            limits:
              cpu: 1
              memory: 1Gi

          livenessProbe:
            httpGet:
              path: /ready
              port: http-metrics
            initialDelaySeconds: 45
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /ready
              port: http-metrics
            initialDelaySeconds: 15
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3

          volumeMounts:
            - name: config
              mountPath: /etc/loki
            - name: index
              mountPath: /data/loki/index
            - name: chunks
              mountPath: /data/loki/chunks
            - name: wal
              mountPath: /data/loki/wal

      volumes:
        - name: config
          secret:
            secretName: loki

      nodeSelector:
        kubernetes.io/os: linux

  volumeClaimTemplates:
    - metadata:
        name: index
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1G
    - metadata:
        name: chunks
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 3G
    - metadata:
        name: wal
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1G
