-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgresql.dist.yaml
119 lines (113 loc) · 2.67 KB
/
postgresql.dist.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
apiVersion: v1
kind: Namespace
metadata:
name: mastodon-server
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
namespace: mastodon-server
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 5Gi
---
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: mastodon-server
spec:
selector:
app: postgres
ports:
- name: postgres-port
protocol: TCP
port: 5432
---
apiVersion: v1
kind: Secret
metadata:
namespace: mastodon-server
name: postgres-secret
type: Opaque
stringData:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: <CHANGE-ME>
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: mastodon
POSTGRES_NON_ROOT_USER: <CHANGE-ME>
POSTGRES_NON_ROOT_PASSWORD: <CHANGE-ME>
---
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-config
namespace: mastodon-server
data:
init-data.sh: |
#!/bin/bash
set -e;
if [ -n "${POSTGRES_NON_ROOT_USER:-}" ] && [ -n "${POSTGRES_NON_ROOT_PASSWORD:-}" ]; then
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER ${POSTGRES_NON_ROOT_USER} WITH PASSWORD '${POSTGRES_NON_ROOT_PASSWORD}';
GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_NON_ROOT_USER};
EOSQL
fi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: mastodon-server
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
name: postgres
spec:
nodeSelector:
kubernetes.io/hostname: worker-1
containers:
- name: postgres
image: ghcr.io/zaherg/postgres:latest
imagePullPolicy: Always
ports:
- name: postgres
containerPort: 5432
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: secrets
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: secrets
key: POSTGRES_PASSWORD
- name: POSTGRES_HOST_AUTH_METHOD
valueFrom:
secretKeyRef:
name: secrets
key: POSTGRES_HOST_AUTH_METHOD
volumes:
- name: secrets
secret:
secretName: postgres-secret
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres-pvc