Skip to content

Commit 3063492

Browse files
feat(#358): postgres cluster 구성 (#359)
Postgres Cluster 구성을 위한 k3d 설정 변경
1 parent e6f3658 commit 3063492

2 files changed

Lines changed: 50 additions & 66 deletions

File tree

infra/k8s/base/postgres.yaml

Lines changed: 37 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,42 @@
1-
apiVersion: v1
2-
kind: PersistentVolumeClaim
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Cluster
33
metadata:
4-
name: postgres-pvc
4+
name: postgres
55
namespace: spot
66
spec:
7-
accessModes:
8-
- ReadWriteOnce
7+
instances: 1
8+
imageName: ghcr.io/cloudnative-pg/postgresql:15
9+
10+
postgresql:
11+
parameters:
12+
max_connections: "300"
13+
max_replication_slots: "10"
14+
max_wal_senders: "10"
15+
pg_hba:
16+
- host replication admin 0.0.0.0/0 md5
17+
18+
bootstrap:
19+
initdb:
20+
database: myapp_db
21+
owner: admin
22+
secret:
23+
name: spot-secrets
24+
25+
storage:
26+
size: 1Gi
27+
pvcTemplate:
28+
accessModes:
29+
- ReadWriteOnce
30+
931
resources:
1032
requests:
11-
storage: 1Gi
12-
---
13-
apiVersion: apps/v1
14-
kind: Deployment
15-
metadata:
16-
name: postgres
17-
namespace: spot
18-
spec:
19-
replicas: 1
20-
selector:
21-
matchLabels:
22-
app: postgres
23-
template:
24-
metadata:
25-
labels:
26-
app: postgres
27-
spec:
28-
containers:
29-
- name: postgres
30-
image: postgres:15-alpine
31-
args: ["-c", "max_connections=300"]
32-
ports:
33-
- containerPort: 5432
34-
env:
35-
- name: POSTGRES_DB
36-
value: "myapp_db"
37-
- name: POSTGRES_USER
38-
value: "admin"
39-
- name: POSTGRES_PASSWORD
40-
valueFrom:
41-
secretKeyRef:
42-
name: spot-secrets
43-
key: SPRING_DATASOURCE_PASSWORD
44-
volumeMounts:
45-
- name: postgres-storage
46-
mountPath: /var/lib/postgresql/data
47-
resources:
48-
requests:
49-
memory: "256Mi"
50-
cpu: "250m"
51-
limits:
52-
memory: "512Mi"
53-
cpu: "500m"
54-
volumes:
55-
- name: postgres-storage
56-
persistentVolumeClaim:
57-
claimName: postgres-pvc
58-
---
59-
apiVersion: v1
60-
kind: Service
61-
metadata:
62-
name: postgres
63-
namespace: spot
64-
spec:
65-
selector:
66-
app: postgres
67-
ports:
68-
- port: 5432
69-
targetPort: 5432
33+
memory: "256Mi"
34+
cpu: "250m"
35+
limits:
36+
memory: "512Mi"
37+
cpu: "500m"
38+
39+
# 이 섹션이 있으면 CNPG가 논리적 복제 기능을 준비합니다.
40+
replicationSlots:
41+
highAvailability:
42+
enabled: true

run_k3d_infra.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ create_cluster() {
7676
log_info "Creating Namespaces..."
7777
kubectl apply -f "$SCRIPT_DIR/infra/k8s/base/namespace.yaml"
7878

79+
kubectl apply --server-side -f \
80+
https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-1.24/releases/cnpg-1.24.0.yaml
81+
82+
log_info "Waiting for CNPG webhook to be ready..."
83+
kubectl wait --for=condition=available deployment/cnpg-controller-manager \
84+
-n cnpg-system --timeout=120s
85+
kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=cloudnative-pg \
86+
-n cnpg-system --timeout=120s
87+
7988
log_info "Cluster created successfully!"
8089
}
8190

@@ -94,10 +103,12 @@ deploy_db() {
94103
fi
95104

96105
log_info "Waiting for DB to be ready..."
97-
kubectl wait --for=condition=available deployment/postgres -n spot --timeout=180s
106+
kubectl wait --for=condition=Ready cluster/postgres -n spot --timeout=180s
107+
log_info "DB deployed successfully!"
108+
log_info "Waiting for Redis to be ready..."
98109
kubectl wait --for=condition=available deployment/redis -n spot --timeout=180s
99110

100-
log_info "DB deployed successfully!"
111+
log_info "Redis deployed successfully!"
101112
}
102113

103114
deploy_monitoring() {

0 commit comments

Comments
 (0)