# Postgres 17, StatefulSet + headless Service. # # StatefulSet rather than Deployment for the stable pod name and a PVC that # survives the pod. --- apiVersion: v1 kind: Service metadata: name: nereus-postgres labels: app.kubernetes.io/name: nereus-postgres app.kubernetes.io/part-of: nereus spec: clusterIP: None selector: app.kubernetes.io/name: nereus-postgres ports: - name: postgres port: 5432 targetPort: postgres --- apiVersion: apps/v1 kind: StatefulSet metadata: name: nereus-postgres labels: app.kubernetes.io/name: nereus-postgres app.kubernetes.io/part-of: nereus spec: serviceName: nereus-postgres replicas: 1 selector: matchLabels: app.kubernetes.io/name: nereus-postgres template: metadata: labels: app.kubernetes.io/name: nereus-postgres app.kubernetes.io/part-of: nereus spec: securityContext: # postgres:17-alpine runs as uid 70. The Debian tags use 999. runAsUser: 70 runAsGroup: 70 fsGroup: 70 runAsNonRoot: true seccompProfile: type: RuntimeDefault containers: - name: postgres image: postgres:17-alpine ports: - name: postgres containerPort: 5432 env: - name: POSTGRES_DB value: nereus - name: POSTGRES_USER value: nereus - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: name: nereus-db key: POSTGRES_PASSWORD # Subdirectory, or initdb trips over lost+found on the volume. - name: PGDATA value: /var/lib/postgresql/data/pgdata volumeMounts: - name: data mountPath: /var/lib/postgresql/data - name: runtime mountPath: /var/run/postgresql - name: tmp mountPath: /tmp readinessProbe: exec: command: ["pg_isready", "-U", "nereus", "-d", "nereus"] initialDelaySeconds: 5 periodSeconds: 5 timeoutSeconds: 3 failureThreshold: 6 livenessProbe: exec: command: ["pg_isready", "-U", "nereus", "-d", "nereus"] initialDelaySeconds: 30 periodSeconds: 15 timeoutSeconds: 5 failureThreshold: 3 securityContext: allowPrivilegeEscalation: false capabilities: drop: ["ALL"] readOnlyRootFilesystem: true resources: requests: cpu: 100m memory: 256Mi limits: memory: 1Gi volumes: - name: runtime emptyDir: {} - name: tmp emptyDir: sizeLimit: 64Mi volumeClaimTemplates: - metadata: name: data spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 5Gi