Skip to content

Commit 4c71fbd

Browse files
committed
Add Kubernetes configuration files for people API and PostgreSQL setup
1 parent 05bfc4f commit 4c71fbd

File tree

8 files changed

+187
-0
lines changed

8 files changed

+187
-0
lines changed

.k8s/api-env.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: api-env
5+
data:
6+
SPRING_PROFILES_ACTIVE: "docker"
7+
SPRING_DATASOURCE_URL: "jdbc:postgresql://db:5432/people"
8+
SPRING_DATASOURCE_USERNAME: "people"
9+
SPRING_DATASOURCE_PASSWORD: "people"
10+
JAVA_OPTS: "-XX:+UseG1GC -XX:MaxRAMPercentage=75"

.k8s/deployment.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: people-api
5+
labels:
6+
app: people-api
7+
spec:
8+
replicas: 3
9+
selector:
10+
matchLabels:
11+
app: people-api
12+
template:
13+
metadata:
14+
labels:
15+
app: people-api
16+
spec:
17+
containers:
18+
- name: people-api
19+
image: mcqueide/people-api:0656d89
20+
ports:
21+
- containerPort: 8080
22+
23+
resources:
24+
requests:
25+
memory: "256Mi"
26+
cpu: "0.5"
27+
limits:
28+
memory: "512Mi"
29+
cpu: "0.75"
30+
31+
envFrom:
32+
- configMapRef:
33+
name: api-env
34+
35+
startupProbe:
36+
httpGet:
37+
path: /actuator/health
38+
port: 8080
39+
failureThreshold: 30
40+
periodSeconds: 10
41+
42+
readinessProbe:
43+
httpGet:
44+
path: /actuator/health
45+
port: 8080
46+
periodSeconds: 10
47+
48+
livenessProbe:
49+
httpGet:
50+
path: /actuator/health
51+
port: 8080
52+
periodSeconds: 20

.k8s/kind.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
4+
nodes:
5+
- role: control-plane
6+
- role: worker
7+
- role: worker
8+
- role: worker

.k8s/postgres-deployment.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: people-api-postgres
5+
labels:
6+
app: people-api-postgres
7+
spec:
8+
selector:
9+
matchLabels:
10+
app: people-api-postgres
11+
template:
12+
metadata:
13+
labels:
14+
app: people-api-postgres
15+
spec:
16+
containers:
17+
- name: db
18+
image: postgres:17-alpine3.22
19+
ports:
20+
- containerPort: 5432
21+
name: postgres
22+
resources:
23+
requests:
24+
memory: "256Mi"
25+
cpu: "250m"
26+
limits:
27+
memory: "512Mi"
28+
cpu: "500m"
29+
env:
30+
- name: POSTGRES_DB
31+
valueFrom:
32+
secretKeyRef:
33+
name: people-api-postgres-secret
34+
key: POSTGRES_DB
35+
- name: POSTGRES_USER
36+
valueFrom:
37+
secretKeyRef:
38+
name: people-api-postgres-secret
39+
key: POSTGRES_USER
40+
- name: POSTGRES_PASSWORD
41+
valueFrom:
42+
secretKeyRef:
43+
name: people-api-postgres-secret
44+
key: POSTGRES_PASSWORD
45+
volumeMounts:
46+
- name: postgres-storage
47+
mountPath: /var/lib/postgresql/data
48+
startupProbe:
49+
exec:
50+
command:
51+
- sh
52+
- -c
53+
- pg_isready -U "$(POSTGRES_USER:-postgres)"
54+
failureThreshold: 30
55+
periodSeconds: 10
56+
readinessProbe:
57+
exec:
58+
command:
59+
- sh
60+
- -c
61+
- pg_isready -U "$(POSTGRES_USER:-postgres)"
62+
periodSeconds: 10
63+
livenessProbe:
64+
exec:
65+
command:
66+
- sh
67+
- -c
68+
- pg_isready -U "$(POSTGRES_USER:-postgres)"
69+
periodSeconds: 20
70+
volumes:
71+
- name: postgres-storage
72+
persistentVolumeClaim:
73+
claimName: postgres-pvc
74+

.k8s/postgres-pvc.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: postgres-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 5Gi

.k8s/postgres-secret.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: people-api-postgres-secret
5+
type: Opaque
6+
stringData:
7+
POSTGRES_DB: "people"
8+
POSTGRES_USER: "people"
9+
POSTGRES_PASSWORD: "people"

.k8s/postgres-service.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: db
5+
spec:
6+
selector:
7+
app: people-api-postgres
8+
type: ClusterIP
9+
ports:
10+
- port: 5432
11+
targetPort: 5432
12+
name: postgres

.k8s/service.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: people-api
5+
spec:
6+
selector:
7+
app: people-api
8+
type: ClusterIP
9+
ports:
10+
- port: 8080
11+
targetPort: 8080
12+
name: http

0 commit comments

Comments
 (0)