-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s.postgres.yaml
156 lines (150 loc) · 3.81 KB
/
k8s.postgres.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#apiVersion: apps/v1
#kind: Deployment
#metadata:
# name: bridge-postgres
#spec:
# replicas: 1
# selector:
# matchLabels:
# app: bridge-postgres
# template:
# metadata:
# labels:
# app: bridge-postgres
# spec:
# containers:
# - name: bridge-postgres
# imagePullPolicy: IfNotPresent
# image: postgres:15.2-alpine3.17
# env:
# - name: POSTGRES_USER
# valueFrom:
# secretKeyRef:
# key: postgres-user
# name: postgres-secret
#
# - name: POSTGRES_PASSWORD
# valueFrom:
# secretKeyRef:
# key: postgres-password
# name: postgres-secret
#
# - name: POSTGRES_DB
# valueFrom:
# configMapKeyRef:
# key: database_name
# name: bridge-api-configmap
#
# - name: POD_IP
# valueFrom:
# fieldRef:
# fieldPath: status.podIP
# apiVersion: v1
# resources:
# limits:
# memory: "2Gi"
# cpu: "1000m"
# ports:
# - containerPort: 5432
---
apiVersion: v1
kind: Service
metadata:
name: bridge-postgres
spec:
selector:
app: bridge-postgres
ports:
- port: 5432
targetPort: 5432
protocol: TCP
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: bridge-postgres
spec:
selector:
matchLabels:
app: bridge-postgres
serviceName: bridge-postgres
replicas: 1
template:
metadata:
labels:
app: bridge-postgres
spec:
initContainers:
- name: bridge-postgres-init
imagePullPolicy: IfNotPresent
image: postgres:15.2-alpine3.17
command:
- bash
- "-c"
- |
set -ex
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
ordinal=${BASH_REMATCH[1]}
if [[ $ordinal -eq 0 ]]; then
printf "I am the primary"
else
printf "I am a read-only replica"
fi
containers:
- name: bridge-postgres
imagePullPolicy: IfNotPresent
image: postgres:15.2-alpine3.17
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
key: postgres-user
name: postgres-secret
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
key: postgres-password
name: postgres-secret
- name: POSTGRES_DB
valueFrom:
configMapKeyRef:
key: database_name
name: bridge-api-configmap
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
apiVersion: v1
ports:
- name: bridge-postgres
containerPort: 5432
livenessProbe:
exec:
command:
- "sh"
- "-c"
- "pg_isready --host $POD_IP"
initialDelaySeconds: 30
periodSeconds: 5
timeoutSeconds: 5
readinessProbe:
exec:
command:
- "sh"
- "-c"
- "pg_isready --host $POD_IP"
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 1
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: bridge-postgres-data
volumeClaimTemplates:
- metadata:
name: bridge-postgres-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi