apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: prometheus
  namespace: monitoring
  labels:
    app: prometheus
    thanos-peer: "true"
spec:
  serviceName: "prometheus"
  replicas: 1
  selector:
    matchLabels:
      app: prometheus
      thanos-peer: "true"
  template:
    metadata:
      labels:
        app: prometheus
        thanos-peer: "true"
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "10902"
    spec:
      serviceAccountName: prometheus
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - prometheus
            topologyKey: kubernetes.io/hostname
      containers:
      - name: prometheus
        image: quay.io/prometheus/prometheus:v2.14.0
        args:
        - "--storage.tsdb.retention=24h"
        - "--config.file=/etc/prometheus-shared/prometheus.yml"
        - "--storage.tsdb.path=/var/prometheus"
        - "--storage.tsdb.min-block-duration=2h"
        - "--storage.tsdb.max-block-duration=2h"
        - "--web.enable-lifecycle"
        ports:
        - name: prom-http
          containerPort: 9090
        volumeMounts:
        - name: config-shared
          mountPath: /etc/prometheus-shared
        - name: rules
          mountPath: /etc/prometheus/rules
        - name: data
          mountPath: /var/prometheus
      - name: thanos-sidecar
        # Always use explicit image tags (release or master-<date>-sha) instead of ambigous `latest` or `master`.
        image: improbable/thanos:v0.1.0-rc.2
        args:
        - "sidecar"
        - "--log.level=debug"
        - "--tsdb.path=/var/prometheus"
        - "--prometheus.url=http://127.0.0.1:9090"
        - "--cluster.peers=thanos-peers.monitoring.svc.cluster.local:10900"
        - "--reloader.config-file=/etc/prometheus/prometheus.yml.tmpl"
        - "--reloader.config-envsubst-file=/etc/prometheus-shared/prometheus.yml"
        - --s3.endpoint=s3.us-west-2.amazonaws.com
        - --s3.bucket=zoox-thanos
        env:
        - name: S3_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: thanos-aws-creds
              key: aws_access_key_id
        - name: S3_SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: thanos-aws-creds
              key: aws_secret_access_key
        ports:
        - name: sidecar-http
          containerPort: 10902
        - name: grpc
          containerPort: 10901
        - name: cluster
          containerPort: 10900
        volumeMounts:
        - name: data
          mountPath: /var/prometheus
        - name: config-shared
          mountPath: /etc/prometheus-shared
        - name: config
          mountPath: /etc/prometheus
      volumes:
      - name: config
        configMap:
          name: prometheus-config
      - name: rules
        configMap:
          name: prometheus-rules
      - name: config-shared
        emptyDir: {}
      - name: data
        emptyDir: {}
