146 lines
2.8 KiB
YAML
146 lines
2.8 KiB
YAML
|
---
|
||
|
apiVersion: v1
|
||
|
kind: PersistentVolume
|
||
|
metadata:
|
||
|
name: postgres-pv
|
||
|
namespace: database
|
||
|
spec:
|
||
|
capacity:
|
||
|
storage: 5Gi
|
||
|
accessModes:
|
||
|
- ReadWriteOnce
|
||
|
persistentVolumeReclaimPolicy: Retain
|
||
|
storageClassName: local-path
|
||
|
hostPath:
|
||
|
path: /dpool/services/postgres/data
|
||
|
|
||
|
---
|
||
|
apiVersion: v1
|
||
|
kind: PersistentVolumeClaim
|
||
|
metadata:
|
||
|
name: postgres-pvc
|
||
|
namespace: database
|
||
|
spec:
|
||
|
accessModes:
|
||
|
- ReadWriteOnce
|
||
|
storageClassName: local-path
|
||
|
resources:
|
||
|
requests:
|
||
|
storage: 5Gi
|
||
|
volumeName: postgres-pv
|
||
|
|
||
|
---
|
||
|
apiVersion: apps/v1
|
||
|
kind: Deployment
|
||
|
metadata:
|
||
|
name: postgres
|
||
|
namespace: database
|
||
|
spec:
|
||
|
replicas: 1
|
||
|
selector:
|
||
|
matchLabels:
|
||
|
app: postgres
|
||
|
template:
|
||
|
metadata:
|
||
|
labels:
|
||
|
app: postgres
|
||
|
spec:
|
||
|
nodeSelector:
|
||
|
role: dck
|
||
|
containers:
|
||
|
- name: postgres
|
||
|
image: postgres:15
|
||
|
ports:
|
||
|
- containerPort: 5432
|
||
|
envFrom:
|
||
|
- secretRef:
|
||
|
name: postgres-secret
|
||
|
volumeMounts:
|
||
|
- name: postgres-data
|
||
|
mountPath: /var/lib/postgresql/data
|
||
|
volumes:
|
||
|
- name: postgres-data
|
||
|
persistentVolumeClaim:
|
||
|
claimName: postgres-pvc
|
||
|
|
||
|
---
|
||
|
apiVersion: v1
|
||
|
kind: Service
|
||
|
metadata:
|
||
|
name: postgres
|
||
|
namespace: database
|
||
|
spec:
|
||
|
selector:
|
||
|
app: postgres
|
||
|
ports:
|
||
|
- port: 5432
|
||
|
targetPort: 5432
|
||
|
|
||
|
---
|
||
|
apiVersion: v1
|
||
|
kind: PersistentVolume
|
||
|
metadata:
|
||
|
name: postgres-backup-pv
|
||
|
spec:
|
||
|
capacity:
|
||
|
storage: 5Gi
|
||
|
accessModes:
|
||
|
- ReadWriteOnce
|
||
|
persistentVolumeReclaimPolicy: Retain
|
||
|
storageClassName: local-path
|
||
|
hostPath:
|
||
|
path: /dpool/services/postgres/backup
|
||
|
|
||
|
---
|
||
|
apiVersion: v1
|
||
|
kind: PersistentVolumeClaim
|
||
|
metadata:
|
||
|
name: postgres-backup-pvc
|
||
|
namespace: database
|
||
|
spec:
|
||
|
accessModes:
|
||
|
- ReadWriteOnce
|
||
|
storageClassName: local-path
|
||
|
resources:
|
||
|
requests:
|
||
|
storage: 5Gi
|
||
|
|
||
|
|
||
|
---
|
||
|
apiVersion: batch/v1
|
||
|
kind: CronJob
|
||
|
metadata:
|
||
|
name: postgres-backup
|
||
|
namespace: database
|
||
|
spec:
|
||
|
schedule: "0 2 * * *" # Every day at 2 AM
|
||
|
jobTemplate:
|
||
|
spec:
|
||
|
template:
|
||
|
spec:
|
||
|
nodeSelector:
|
||
|
role: dck
|
||
|
restartPolicy: OnFailure
|
||
|
containers:
|
||
|
- name: pg-backup
|
||
|
image: postgres:15
|
||
|
envFrom:
|
||
|
- secretRef:
|
||
|
name: postgres-secret
|
||
|
command:
|
||
|
- /bin/sh
|
||
|
- -c
|
||
|
- |
|
||
|
mkdir -p /backup
|
||
|
PGPASSWORD=$POSTGRES_PASSWORD pg_dump -U $POSTGRES_USER -h localhost $POSTGRES_DB > /backup/backup-$(date +'%Y-%m-%d').sql
|
||
|
volumeMounts:
|
||
|
- name: backup-volume
|
||
|
mountPath: /backup
|
||
|
volumes:
|
||
|
- name: backup-volume
|
||
|
persistentVolumeClaim:
|
||
|
claimName: postgres-backup-pvc
|
||
|
|
||
|
|
||
|
|