kube/shared/postgres.yml

87 lines
1.8 KiB
YAML
Raw Permalink Normal View History

2022-08-16 09:40:54 +00:00
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
serviceName: postgres
selector:
matchLabels:
app: postgres
replicas: 1
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: exporter
image: prometheuscommunity/postgres-exporter:latest
env:
- name: DATA_SOURCE_NAME
value: exporter@tcp(127.0.0.1)/
- name: postgres
image: postgres:latest
securityContext:
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 999
env:
- name: POSTGRES_USER
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POSTGRES_DB
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secrets
key: POSTGRES_PASSWORD
volumeMounts:
- mountPath: /var/lib/postgresql
name: postgres-data
- mountPath: /var/run/postgresql
name: postgres-run
volumes:
- name: postgres-run
emptyDir:
medium: Memory
sizeLimit: 1Mi
volumeClaimTemplates:
- metadata:
name: postgres-data
spec:
storageClassName: longhorn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
ports:
- protocol: TCP
port: 5432
selector:
app: postgres
---
apiVersion: v1
kind: Service
metadata:
name: postgres-exporter
annotations:
prometheus.io/scrape: 'true'
spec:
ports:
- protocol: TCP
port: 9187
selector:
app: exporter