Skip to content

Commit acedb1a

Browse files
committed
PEER-244,245: Add Question Service Deployment
Signed-off-by: SeeuSim <[email protected]>
1 parent 99d9103 commit acedb1a

File tree

6 files changed

+137
-3
lines changed

6 files changed

+137
-3
lines changed

backend/question/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export const dbConfig = {
1111
user: process.env.POSTGRES_USER,
1212
password: process.env.POSTGRES_PASSWORD,
1313
};
14+
15+
export const LOAD_TEST_POD = process.env.LOAD_TEST_POD || 'http://user-service-load-test';

backend/question/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import helmet from 'helmet';
77
import { StatusCodes } from 'http-status-codes';
88
import pino from 'pino-http';
99

10-
import { UI_HOST } from '@/config';
10+
import { LOAD_TEST_POD, UI_HOST } from '@/config';
1111
import { config, db } from '@/lib/db';
1212
import { logger } from '@/lib/utils';
1313
import questionsRouter from '@/routes/question';
@@ -32,7 +32,7 @@ app.use(json());
3232
app.use(helmet());
3333
app.use(
3434
cors({
35-
origin: [UI_HOST],
35+
origin: [UI_HOST, LOAD_TEST_POD],
3636
credentials: true,
3737
})
3838
);
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: question-service
5+
namespace: peerprep
6+
labels:
7+
project: peerprep
8+
peerprep.service: question-service
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
project: peerprep
14+
peerprep.service: question-service
15+
strategy:
16+
type: Recreate
17+
template:
18+
metadata:
19+
labels:
20+
project: peerprep
21+
peerprep.service: question-service
22+
peerprep.network.question-api: "true"
23+
peerprep.network.question-db: "true"
24+
spec:
25+
initContainers:
26+
- name: wait-for-postgres
27+
image: postgres:16.4
28+
env:
29+
- name: PGHOST
30+
valueFrom:
31+
secretKeyRef:
32+
name: question-secret
33+
key: EXPRESS_DB_HOST
34+
- name: PGPORT
35+
valueFrom:
36+
secretKeyRef:
37+
name: question-secret
38+
key: EXPRESS_DB_PORT
39+
- name: PGPASSWORD
40+
valueFrom:
41+
secretKeyRef:
42+
name: question-secret
43+
key: POSTGRES_PASSWORD
44+
- name: PGUSER
45+
valueFrom:
46+
secretKeyRef:
47+
name: question-secret
48+
key: POSTGRES_USER
49+
- name: PGDATABASE
50+
valueFrom:
51+
secretKeyRef:
52+
name: question-secret
53+
key: POSTGRES_DB
54+
command:
55+
- /bin/sh
56+
- -c
57+
- |
58+
while ! psql -c 'SELECT 1' > /dev/null 2>&1; do
59+
echo "Waiting for $PGDATABASE"
60+
sleep 1
61+
done
62+
echo "$PGDATABASE is ready!"
63+
64+
containers:
65+
- name: question-express
66+
image: ay2425s1cs3219g16/question-express:main
67+
# image: ay2425s1cs3219g16/question-express:sha-ff94455
68+
imagePullPolicy: IfNotPresent
69+
envFrom:
70+
- secretRef:
71+
name: question-secret
72+
env:
73+
- name: LOAD_TEST_POD
74+
value: http://question-service-load-test
75+
livenessProbe:
76+
exec:
77+
command:
78+
- /bin/sh
79+
- -c
80+
- wget --no-verbose --tries=1 --spider http://localhost:9002/health || exit 1
81+
periodSeconds: 30
82+
initialDelaySeconds: 5
83+
timeoutSeconds: 10
84+
failureThreshold: 5
85+
ports:
86+
- name: question-svc-ctr
87+
containerPort: 9002
88+
resources:
89+
requests:
90+
cpu: 250m
91+
memory: 256Mi
92+
limits:
93+
cpu: 500m
94+
memory: 512Mi
95+

k8s/04-question-svc-hpa.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: autoscaling/v2
2+
kind: HorizontalPodAutoscaler
3+
metadata:
4+
name: question-service-hpa
5+
namespace: peerprep
6+
spec:
7+
scaleTargetRef:
8+
apiVersion: apps/v1
9+
kind: Deployment
10+
name: question-service
11+
minReplicas: 1
12+
maxReplicas: 5
13+
metrics:
14+
- type: Resource
15+
resource:
16+
name: cpu
17+
target:
18+
type: Utilization
19+
averageUtilization: 30

k8s/04-question-svc-service.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: question-service
5+
namespace: peerprep
6+
labels:
7+
project: peerprep
8+
peerprep.service: question-service
9+
spec:
10+
type: ClusterIP
11+
selector:
12+
project: peerprep
13+
peerprep.service: question-service
14+
ports:
15+
- name: question-svc-prt
16+
port: 9002
17+
targetPort: question-svc-ctr

k8s/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Prerequisites
44

5-
- Minikube
5+
- [**Minikube**](https://minikube.sigs.k8s.io/docs/)
6+
67
To run a local Kubernetes cluster, we
78
recommend using Minikube on your local machine.
89

0 commit comments

Comments
 (0)