Skip to content

Commit 813188d

Browse files
Refactor/344 k3d shell (#346)
run_k3d.sh 수행 시 Argo 실행에서 k8s 실행 속도 지연이 발생하여 infra 설정이 자주 변경되는 kafka와 spring boot 어플리케이션과 자주 변경되지 않는 Argo, DB, Redis를 분리해서 동작할 수 있도록 변경이 필요합니다. ### 변경사항 - run_k3d.sh 를 run_k3d_app.sh 와 run_k3d_infra.sh로 분리 - run_k3d_app.sh에 현재 빌드 진행 사항 확인할 수 있는 로직 추가
1 parent 6a3cc48 commit 813188d

7 files changed

Lines changed: 143 additions & 121 deletions

File tree

infra/k8s/apps/kustomization.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
# Spot Apps
6+
- spot-ingress.yaml
7+
- spot-gateway.yaml
8+
- spot-user.yaml
9+
- spot-store.yaml
10+
- spot-order.yaml
11+
- spot-payment.yaml
12+
13+
# Spot ServiceMonitors
14+
- ../base/monitoring/servicemonitors/spot-gateway-servicemonitor.yaml
15+
- ../base/monitoring/servicemonitors/spot-user-servicemonitor.yaml
16+
- ../base/monitoring/servicemonitors/spot-order-servicemonitor.yaml
17+
- ../base/monitoring/servicemonitors/spot-store-servicemonitor.yaml
18+
- ../base/monitoring/servicemonitors/spot-payment-servicemonitor.yaml
19+
20+
configMapGenerator:
21+
- name: spot-app-config
22+
namespace: spot
23+
files:
24+
- ../../../config/common.yml
25+
- ../../../config/kafka-topics.yml
26+
- ../../../config/spot-gateway.yml
27+
- ../../../config/spot-user.yml
28+
- ../../../config/spot-store.yml
29+
- ../../../config/spot-order.yml
30+
- ../../../config/spot-payment.yml
31+
options:
32+
disableNameSuffixHash: true
33+
34+
secretGenerator:
35+
- name: spot-secrets
36+
namespace: spot
37+
envs:
38+
- ../../../.env
39+
options:
40+
disableNameSuffixHash: true
41+
42+
generatorOptions:
43+
disableNameSuffixHash: true

infra/k8s/base/kustomization.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
# Base
6+
- ./namespace.yaml
7+
- ./configmap.yaml
8+
9+
# Kafka
10+
- ./kafka/kafka.yaml
11+
- ./kafka/kafka-nodepool.yml
12+
- ./kafka/kafka-connect.yaml
13+
- ./kafka/connectors.yaml
14+
- ./kafka/kafka-ui.yaml
15+
- ./kafka/allow-kafka-ui-netpol.yaml
16+
17+
# Temporal
18+
- ./temporal/temporal.yaml
19+
- ./temporal/temporal-ui.yaml
20+
21+
configMapGenerator:
22+
- name: kafka-connect-init-config
23+
namespace: spot
24+
files:
25+
- ../../../connectors/order-outbox.json
26+
- ../../../connectors/payment-outbox.json
27+
- ../../../connectors/register-connectors.sh
28+
options:
29+
disableNameSuffixHash: true
30+
31+
generatorOptions:
32+
disableNameSuffixHash: true

infra/k8s/kustomization.yaml

Lines changed: 8 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,13 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33

4-
# namespace: spot 제거 - 각 리소스가 자체 네임스페이스 유지
4+
# 전체 배포 시 사용 (infra + apps + monitoring 포함)
5+
# 개별 배포는 각 서브 디렉토리 kustomization 사용:
6+
# - infra/k8s/infra/ (Kafka, Temporal)
7+
# - infra/k8s/apps/ (Spot Apps, ServiceMonitors)
8+
# - infra/k8s/monitoring/ (Grafana Dashboard ConfigMaps)
59

610
resources:
7-
# Base
8-
- base/namespace.yaml
9-
- base/configmap.yaml
10-
# - base/postgres.yaml
11-
# - base/redis.yaml
12-
13-
# Kafka
14-
- base/kafka/kafka.yaml
15-
- base/kafka/kafka-nodepool.yml
16-
- base/kafka/kafka-connect.yaml
17-
- base/kafka/connectors.yaml
18-
- base/kafka/kafka-ui.yaml
19-
- base/kafka/allow-kafka-ui-netpol.yaml
20-
21-
# temporal
22-
- base/temporal/temporal.yaml
23-
- base/temporal/temporal-ui.yaml
24-
25-
# Monitoring & Logging
26-
- base/monitoring/loki/loki.yaml
27-
- base/monitoring/loki/loki-config.yaml
28-
- base/monitoring/monitoring-ingress.yaml
29-
- base/monitoring/fluent-bit/fluent-bit.yaml
30-
- base/monitoring/fluent-bit/fluent-bit-config.yaml
31-
32-
# Grafana
33-
- base/monitoring/grafana/grafana.yaml
34-
- base/monitoring/grafana/grafana-config.yaml
35-
36-
# Spot Monitoring
37-
- base/monitoring/servicemonitors/spot-gateway-servicemonitor.yaml
38-
- base/monitoring/servicemonitors/spot-user-servicemonitor.yaml
39-
- base/monitoring/servicemonitors/spot-order-servicemonitor.yaml
40-
- base/monitoring/servicemonitors/spot-store-servicemonitor.yaml
41-
- base/monitoring/servicemonitors/spot-payment-servicemonitor.yaml
42-
43-
# Spot Apps
44-
- apps/spot-ingress.yaml
45-
- apps/spot-gateway.yaml
46-
- apps/spot-user.yaml
47-
- apps/spot-store.yaml
48-
- apps/spot-order.yaml
49-
- apps/spot-payment.yaml
50-
51-
# config 디렉토리의 yml 파일들을 ConfigMap으로 생성
52-
configMapGenerator:
53-
- name: spot-app-config
54-
namespace: spot
55-
files:
56-
- ../../config/common.yml
57-
- ../../config/kafka-topics.yml
58-
- ../../config/spot-gateway.yml
59-
- ../../config/spot-user.yml
60-
- ../../config/spot-store.yml
61-
- ../../config/spot-order.yml
62-
- ../../config/spot-payment.yml
63-
options:
64-
disableNameSuffixHash: true
65-
66-
- name: kafka-connect-init-config
67-
namespace: spot
68-
files:
69-
- ../../connectors/order-outbox.json
70-
- ../../connectors/payment-outbox.json
71-
- ../../connectors/register-connectors.sh
72-
options:
73-
disableNameSuffixHash: true
74-
75-
- name: grafana-dashboards-spot
76-
namespace: monitoring
77-
files:
78-
- base/monitoring/grafana/dashboards/spot-logs.json
79-
80-
- name: grafana-dashboards-9578
81-
namespace: monitoring
82-
files:
83-
- base/monitoring/grafana/dashboards/9578.json
84-
85-
- name: grafana-dashboards-15760
86-
namespace: monitoring
87-
files:
88-
- base/monitoring/grafana/dashboards/15760.json
89-
90-
- name: grafana-dashboards-15757
91-
namespace: monitoring
92-
files:
93-
- base/monitoring/grafana/dashboards/15757.json
94-
95-
- name: grafana-dashboards-15661
96-
namespace: monitoring
97-
files:
98-
- base/monitoring/grafana/dashboards/15661.json
99-
100-
secretGenerator:
101-
- name: spot-secrets
102-
namespace: spot
103-
envs:
104-
- ../../.env
105-
options:
106-
disableNameSuffixHash: true
107-
108-
109-
generatorOptions:
110-
disableNameSuffixHash: true
11+
- base/
12+
- apps/
13+
- monitoring/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
configMapGenerator:
5+
- name: grafana-dashboards-spot
6+
namespace: monitoring
7+
files:
8+
- ../base/monitoring/grafana/dashboards/spot-logs.json
9+
10+
- name: grafana-dashboards-9578
11+
namespace: monitoring
12+
files:
13+
- ../base/monitoring/grafana/dashboards/9578.json
14+
15+
- name: grafana-dashboards-15760
16+
namespace: monitoring
17+
files:
18+
- ../base/monitoring/grafana/dashboards/15760.json
19+
20+
- name: grafana-dashboards-15757
21+
namespace: monitoring
22+
files:
23+
- ../base/monitoring/grafana/dashboards/15757.json
24+
25+
- name: grafana-dashboards-15661
26+
namespace: monitoring
27+
files:
28+
- ../base/monitoring/grafana/dashboards/15661.json
29+
30+
generatorOptions:
31+
disableNameSuffixHash: true

run_k3d.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
./run_k3d_infra.sh
2+
./run_k3d_app.sh

run_k3d_app.sh

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,29 +126,27 @@ build_and_push_images() {
126126
install_strimzi() {
127127
log_info "Installing Strimzi Kafka Operator via Helm..."
128128

129-
kubectl create namespace strimzi --dry-run=client -o yaml | kubectl apply -f -
130129
kubectl create namespace spot --dry-run=client -o yaml | kubectl apply -f -
131-
130+
132131
helm repo add strimzi https://strimzi.io/charts/ >/dev/null 2>&1 || true
133132
helm repo update
134133

135-
helm upgrade --install strimzi-operator strimzi/strimzi-kafka-operator \
136-
-n strimzi \
137-
--set watchNamespaces={spot} \
138-
--wait
134+
helm install strimzi-operator strimzi/strimzi-kafka-operator \
135+
--namespace kafka \
136+
--create-namespace \
137+
--set crds.enabled=true
139138

140139
log_info "Strimzi Operator installed successfully!"
141140
}
142141

143-
deploy_all() {
144-
log_info "Deploying all resources using Kustomize..."
142+
deploy_infra() {
143+
log_info "Deploying infra resources (Kafka, Temporal)..."
145144

146145
# Ingress Controller 설치
147146
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.14.3/deploy/static/provider/cloud/deploy.yaml
148147
kubectl wait --for=condition=ready pod -n ingress-nginx --selector=app.kubernetes.io/component=controller --timeout=120s
149148

150-
# Kustomize 배포
151-
kustomize build "$SCRIPT_DIR/infra/k8s/" --load-restrictor LoadRestrictionsNone | kubectl apply -f -
149+
kustomize build "$SCRIPT_DIR/infra/k8s/base/" --load-restrictor LoadRestrictionsNone | kubectl apply -f -
152150

153151
log_info "Waiting for Kafka Cluster (KRaft)..."
154152
kubectl wait --for=condition=Ready kafka/spot-cluster -n spot --timeout=300s
@@ -158,12 +156,20 @@ deploy_all() {
158156

159157
log_info "Waiting for Kafka UI..."
160158
kubectl wait --for=condition=available deployment/kafka-ui -n spot --timeout=180s
161-
159+
162160
log_info "Waiting for Temporal..."
163161
kubectl wait --for=condition=available deployment/temporal -n spot --timeout=180s
164162
kubectl wait --for=condition=available deployment/temporal-ui -n spot --timeout=180s
165163

166-
log_info "Infrastructure deployed successfully!"
164+
log_info "Infra deployed successfully!"
165+
}
166+
167+
deploy_apps() {
168+
log_info "Deploying Spot app resources..."
169+
170+
kustomize build "$SCRIPT_DIR/infra/k8s/apps/" --load-restrictor LoadRestrictionsNone | kubectl apply -f -
171+
172+
log_info "Spot apps deployed successfully!"
167173
}
168174

169175

@@ -197,7 +203,8 @@ main() {
197203
exit 0
198204
;;
199205
--deploy-only)
200-
deploy_all
206+
deploy_infra
207+
deploy_apps
201208
exit 0
202209
;;
203210
esac
@@ -207,8 +214,9 @@ main() {
207214
create_cluster
208215
build_and_push_images
209216
install_strimzi
210-
deploy_all
217+
deploy_infra
218+
deploy_apps
211219
show_status
212220
}
213221

214-
main "$@"
222+
main "$@"

run_k3d_infra.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ deploy_monitoring() {
127127
log_info "Waiting for Fluent-bit to be ready..."
128128
kubectl rollout status daemonset/fluent-bit-daemon -n monitoring --timeout=180s
129129

130+
log_info "Applying Grafana dashboard ConfigMaps..."
131+
kustomize build "$SCRIPT_DIR/infra/k8s/monitoring/" --load-restrictor LoadRestrictionsNone | kubectl apply -f -
132+
130133
log_info "Monitoring stack deployed successfully!"
131134
}
132135

@@ -207,4 +210,4 @@ main() {
207210
show_status
208211
}
209212

210-
main "$@"
213+
main "$@"

0 commit comments

Comments
 (0)