apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  namespace: sonarqube
  labels:
    app: postgres
spec:
  selector:
    matchLabels:
      app: postgres
  serviceName: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      serviceAccountName: postgres
      containers:
        - name: postgres
          image: postgres:10.3-alpine
          env:
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgres
                  key: password
            - name: PGDATA
              value: /var/lib/postgresql/data/pgdata
          ports:
            - name: postgres
              containerPort: 5432
          resources:
            limits:
              memory: 1Gi
              cpu: 1
            requests:
              memory: 100Mi
              cpu: 200m
          livenessProbe:
            tcpSocket:
              port: postgres
            initialDelaySeconds: 30
            timeoutSeconds: 1
            periodSeconds: 5
          readinessProbe:
            tcpSocket:
              port: postgres
            initialDelaySeconds: 5
            timeoutSeconds: 1
            periodSeconds: 5
          volumeMounts:
            - name: data
              mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 8Gi
