Postgres

LogZilla documentation for Postgres

PostgreSQL manifest

yaml
apiVersion: v1
kind: Secret
metadata:
  name: postgres-secret
type: Opaque
stringData:
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: <set-strong-password>
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-multimap
data:
  POSTGRES_DB: logzilla
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: postgres
  selector:
    matchLabels:
      name: postgres
  template:
    metadata:
      labels:
        name: postgres
    spec:
      containers:
      - name: postgres
        image: library/postgres:17.2-alpine
        args:
          - postgres
          - -c
          - max_connections=500
        resources:
          requests:
            memory: 500Mi
            cpu: 500m
          limits:
            memory: 1Gi
            cpu: 1000m
        ports:
        - containerPort: 5432
        livenessProbe:
          exec:
            command: [
              "pg_isready",
              "-U", "$(POSTGRES_USER)",
              "-d", "$(POSTGRES_DB)"
            ]
          failureThreshold: 5
          periodSeconds: 1
          timeoutSeconds: 15
        readinessProbe:
          exec:
            command: [
              "pg_isready",
              "-U", "$(POSTGRES_USER)",
              "-d","$(POSTGRES_DB)"
            ]
          initialDelaySeconds: 20
          timeoutSeconds: 5
          periodSeconds: 3
          failureThreshold: 2
          successThreshold: 1
        volumeMounts:
        - name: postgres
          mountPath: /var/lib/postgresql/
          readOnly: false
        env:
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: postgres-secret
              key: POSTGRES_PASSWORD
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: postgres-secret
              key: POSTGRES_USER
        - name: POSTGRES_DB
          valueFrom:
            configMapKeyRef:
              name: postgres-multimap
              key: POSTGRES_DB
      volumes:
        - name: postgres
          persistentVolumeClaim:
            claimName: postgres-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: postgres
spec:
  ports:
    - port: 5432
      targetPort: 5432
      protocol: TCP
  type: ClusterIP
  selector:
    name: postgres

Notes

  • Replace placeholder values in postgres-secret with environment-specific strong credentials. Examples use stringData for readability.
  • If you prefer data: instead of stringData, base64-encode values.
  • The readiness/liveness probe uses variables for database name and user. Ensure the variable names match the environment (for example, POSTGRES_DB).
Postgres | LogZilla Documentation