---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  namespace: thanos
  name: storegateway
spec:
  replicas: 1
  serviceName: storegateway
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app.kubernetes.io/name: storegateway
  template:
    metadata:
      labels:
        app.kubernetes.io/name: storegateway
    spec:
      serviceAccount: thanos
      securityContext:
        fsGroup: 1001
      initContainers:
        - name: init-chmod-data
          image: docker.io/bitnami/minideb:buster
          command:
            - sh
            - -c
            - |
              mkdir -p /data
              chown -R "1001:1001" /data
          securityContext:
            runAsUser: 0
          volumeMounts:
            - name: data
              mountPath: /data
      containers:
        - name: storegateway
          image: quay.io/thanos/thanos:v0.37.2
          securityContext:
            runAsUser: 1001
          args:
            - store
            - --chunk-pool-size=2GB
            - --log.level=debug
            - --grpc-address=0.0.0.0:10901
            - --http-address=0.0.0.0:10902
            - --data-dir=/data
            - --objstore.config-file=/conf/objstore.yml
          ports:
            - name: http
              containerPort: 10902
              protocol: TCP
            - name: grpc
              containerPort: 10901
              protocol: TCP
          livenessProbe:
            failureThreshold: 6
            httpGet:
              path: /-/healthy
              port: http
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 30
          readinessProbe:
            failureThreshold: 6
            httpGet:
              path: /-/ready
              port: http
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 30
          resources:
            requests:
              cpu: 200m
              memory: 512Mi
            limits:
              cpu: 1000m
              memory: 5Gi
          volumeMounts:
            - name: objstore
              mountPath: /conf/objstore.yml
              subPath: objstore.yml
            - name: data
              mountPath: /data
      volumes:
        - name: objstore
          secret:
            secretName: objstore
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: [ReadWriteOnce]
        resources:
          requests:
            storage: 20Gi
---
apiVersion: v1
kind: Service
metadata:
  namespace: thanos
  name: storegateway
spec:
  type: ClusterIP
  ports:
    - port: 9090
      targetPort: http
      protocol: TCP
      name: http
    - port: 10901
      targetPort: grpc
      protocol: TCP
      name: grpc
  selector:
    app.kubernetes.io/name: storegateway