apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: postgres
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: postgres
        image: postgres:10-alpine
        ports:
        - containerPort: 5432
        volumeMounts:
        - name: postgres
          mountPath: /var/lib/postgresql/data
        env:
        - name: POSTGRES_DB
          value: sonarqube
        - name: POSTGRES_USER
          value: sonarqube
        - name: PGDATA
          value: /var/lib/postgresql/data/pgdata
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: postgres
              key: password
        resources:
          requests:
            memory: "64Mi"
            cpu: "200m"
          limits:
            memory: "1000Mi"
            cpu: "1000m"

  volumeClaimTemplates:
  - metadata:
      name: postgres
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
