Skip to content

Commit 0751694

Browse files
committed
create postgres db manifest for k8s deployment
1 parent ffc8410 commit 0751694

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

k8s/database.yaml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
# Namespace for database
3+
apiVersion: v1
4+
kind: Namespace
5+
metadata:
6+
name: student-api
7+
---
8+
# ConfigMap for database host, port, and DB name
9+
apiVersion: v1
10+
kind: ConfigMap
11+
metadata:
12+
name: postgres-config
13+
namespace: student-api
14+
data:
15+
POSTGRES_HOST: postgres
16+
POSTGRES_PORT: "5432"
17+
POSTGRES_DB: studentdb
18+
---
19+
# PersistentVolumeClaim for Postgres storage
20+
apiVersion: v1
21+
kind: PersistentVolumeClaim
22+
metadata:
23+
name: postgres-pvc
24+
namespace: student-api
25+
spec:
26+
accessModes:
27+
- ReadWriteOnce
28+
resources:
29+
requests:
30+
storage: 1Gi
31+
---
32+
# Deployment for Postgres
33+
apiVersion: apps/v1
34+
kind: Deployment
35+
metadata:
36+
name: postgres
37+
namespace: student-api
38+
spec:
39+
replicas: 1
40+
selector:
41+
matchLabels:
42+
app: postgres
43+
template:
44+
metadata:
45+
labels:
46+
app: postgres
47+
spec:
48+
nodeSelector:
49+
type: database
50+
containers:
51+
- name: postgres
52+
image: postgres:15
53+
ports:
54+
- containerPort: 5432
55+
env:
56+
# Secrets for username & password
57+
- name: POSTGRES_USER
58+
valueFrom:
59+
secretKeyRef:
60+
name: postgres-secret
61+
key: POSTGRES_USER
62+
- name: POSTGRES_PASSWORD
63+
valueFrom:
64+
secretKeyRef:
65+
name: postgres-secret
66+
key: POSTGRES_PASSWORD
67+
# ConfigMap for DB name, host, port
68+
- name: POSTGRES_DB
69+
valueFrom:
70+
configMapKeyRef:
71+
name: postgres-config
72+
key: POSTGRES_DB
73+
- name: POSTGRES_HOST
74+
valueFrom:
75+
configMapKeyRef:
76+
name: postgres-config
77+
key: POSTGRES_HOST
78+
- name: POSTGRES_PORT
79+
valueFrom:
80+
configMapKeyRef:
81+
name: postgres-config
82+
key: POSTGRES_PORT
83+
volumeMounts:
84+
- name: postgres-storage
85+
mountPath: /var/lib/postgresql/data
86+
volumes:
87+
- name: postgres-storage
88+
persistentVolumeClaim:
89+
claimName: postgres-pvc
90+
---
91+
# Service to expose Postgres
92+
apiVersion: v1
93+
kind: Service
94+
metadata:
95+
name: postgres
96+
namespace: student-api
97+
spec:
98+
selector:
99+
app: postgres
100+
ports:
101+
- protocol: TCP
102+
port: 5432
103+
targetPort: 5432
104+
type: ClusterIP

0 commit comments

Comments
 (0)