diff --git a/infra/k8s/base/configmap.yaml b/infra/k8s/base/configmap.yaml deleted file mode 100644 index c36d287e..00000000 --- a/infra/k8s/base/configmap.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: spot-common-config - namespace: spot -data: - SPRING_DATASOURCE_URL: "jdbc:postgresql://postgres:5432/myapp_db" - SPRING_DATASOURCE_USERNAME: "admin" - SPRING_DATA_REDIS_HOST: "redis" - SPRING_DATA_REDIS_PORT: "6379" - KAFKA_BOOTSTRAP_SERVERS: "kafka:9092" ---- -apiVersion: v1 -kind: Secret -metadata: - name: monitoring-secrets - namespace: monitoring -type: Opaque -stringData: - GF_SECURITY_ADMIN_USER: "spot" - GF_SECURITY_ADMIN_PASSWORD: "spot-grafana" ---- diff --git a/infra/k8s/base/kafka/kafka-ui.yaml b/infra/k8s/base/kafka/kafka-ui.yaml index 5ab3dab2..30103268 100644 --- a/infra/k8s/base/kafka/kafka-ui.yaml +++ b/infra/k8s/base/kafka/kafka-ui.yaml @@ -18,10 +18,6 @@ spec: image: provectuslabs/kafka-ui:latest ports: - containerPort: 8080 - resources: - requests: - memory: "384Mi" - cpu: "100m" env: - name: KAFKA_CLUSTERS_0_NAME value: spot-cluster @@ -39,6 +35,13 @@ spec: value: WARN - name: LOGGING_LEVEL_COM_PROVECTUS value: WARN + resources: + requests: + cpu: "100m" + memory: "256Mi" + limits: + cpu: "500m" + memory: "512Mi" --- apiVersion: v1 kind: Service diff --git a/infra/k8s/base/secrets.yaml b/infra/k8s/base/secrets.yaml new file mode 100644 index 00000000..85331daf --- /dev/null +++ b/infra/k8s/base/secrets.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: monitoring-secrets + namespace: monitoring +type: Opaque +stringData: + GF_SECURITY_ADMIN_USER: "spot" + GF_SECURITY_ADMIN_PASSWORD: "spot-grafana" \ No newline at end of file diff --git a/infra/k8s/base/temporal/temporal-ui.yaml b/infra/k8s/base/temporal/temporal-ui.yaml index fc642a9a..6fc61d79 100644 --- a/infra/k8s/base/temporal/temporal-ui.yaml +++ b/infra/k8s/base/temporal/temporal-ui.yaml @@ -23,7 +23,15 @@ spec: value: "temporal:7233" - name: TEMPORAL_CORS_ALLOW_ORIGINS value: "*" + resources: + requests: + memory: "128Mi" + cpu: "100m" + limits: + memory: "512Mi" + cpu: "500m" --- +# Service apiVersion: v1 kind: Service metadata: diff --git a/infra/k8s/base/temporal/temporal.yaml b/infra/k8s/base/temporal/temporal.yaml index ab115462..d5c37201 100644 --- a/infra/k8s/base/temporal/temporal.yaml +++ b/infra/k8s/base/temporal/temporal.yaml @@ -50,8 +50,8 @@ spec: memory: "256Mi" cpu: "250m" limits: - memory: "512Mi" - cpu: "500m" + memory: "1Gi" + cpu: "750m" --- apiVersion: v1 kind: Service diff --git a/infra/k8s/kustomization.yaml b/infra/k8s/kustomization.yaml index 51a2819a..0f73dede 100644 --- a/infra/k8s/kustomization.yaml +++ b/infra/k8s/kustomization.yaml @@ -6,7 +6,7 @@ kind: Kustomization resources: # Base - base/namespace.yaml - - base/configmap.yaml + - base/secrets.yaml # - base/postgres.yaml # - base/redis.yaml @@ -40,14 +40,6 @@ resources: - base/monitoring/servicemonitors/spot-store-servicemonitor.yaml - base/monitoring/servicemonitors/spot-payment-servicemonitor.yaml - # Spot Apps - - apps/spot-ingress.yaml - - apps/spot-gateway.yaml - - apps/spot-user.yaml - - apps/spot-store.yaml - - apps/spot-order.yaml - - apps/spot-payment.yaml - # config 디렉토리의 yml 파일들을 ConfigMap으로 생성 configMapGenerator: - name: spot-app-config @@ -63,15 +55,6 @@ configMapGenerator: options: disableNameSuffixHash: true - - name: kafka-connect-init-config - namespace: spot - files: - - ../../connectors/order-outbox.json - - ../../connectors/payment-outbox.json - - ../../connectors/register-connectors.sh - options: - disableNameSuffixHash: true - - name: grafana-dashboards-spot namespace: monitoring files: @@ -105,6 +88,5 @@ secretGenerator: options: disableNameSuffixHash: true - generatorOptions: disableNameSuffixHash: true \ No newline at end of file diff --git a/infra/spot-apps/.helmignore b/infra/spot-apps/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/infra/spot-apps/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/infra/spot-apps/Chart.yaml b/infra/spot-apps/Chart.yaml new file mode 100644 index 00000000..854d5b1a --- /dev/null +++ b/infra/spot-apps/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: spot-apps +description: Spot 프로젝트 app 설정 +type: application +version: 0.1.0 +appVersion: "1.0.0" \ No newline at end of file diff --git a/infra/spot-apps/templates/deployment.yaml b/infra/spot-apps/templates/deployment.yaml new file mode 100644 index 00000000..fe46c4c7 --- /dev/null +++ b/infra/spot-apps/templates/deployment.yaml @@ -0,0 +1,81 @@ +{{- range $key, $val := .Values.apps }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ $val.name }} + labels: + app: {{ $val.name }} +spec: + replicas: {{ $.Values.global.replicas | default 1}} + selector: + matchLabels: + app: {{ $val.name }} + template: + metadata: + labels: + app: {{ $val.name }} + spec: + containers: + - name: {{ $val.name }} + image: {{ $.Values.global.repository }}/{{ $val.name }}:latest + imagePullPolicy: {{ $.Values.global.imagePullPolicy }} + ports: + - containerPort: {{ $val.targetPort | default $val.port }} + env: + - name: SPRING_PROFILES_ACTIVE + value: {{ $.Values.env.activeProfile }} + - name: LOGGING_CONFIG + value: {{ $.Values.env.loggingConfig }} + envFrom: + - secretRef: + name: {{ $.Values.config.secretName }} + + # 리소스 설정 + resources: + requests: + cpu: {{ $.Values.global.requests.cpu }} + memory: {{ $.Values.global.requests.memory}} + limits: + cpu: {{ $.Values.global.limits.cpu }} + memory: {{ $.Values.global.limits.memory }} + + # 헬스 체크 + readinessProbe: + httpGet: + path: {{ $.Values.global.path }} + port: {{ $val.targetPort | default $val.port }} + initialDelaySeconds: {{ $.Values.global.readiness.initial }} + periodSeconds: {{ $.Values.global.readiness.period }} + {{- if $val.timeoutSeconds }} + timeoutSeconds: {{ $val.timeoutSeconds }} + {{- end }} + {{- if $val.failureThreshold }} + failureThreshold: {{ $val.failureThreshold }} + {{- end }} + {{- if $val.successThreshold }} + successThreshold: {{ $val.successThreshold }} + {{- end }} + + # 헬스 체크 (Liveness) + livenessProbe: + httpGet: + path: {{ $.Values.global.path }} + port: {{ $val.targetPort | default $val.port }} + initialDelaySeconds: {{ $.Values.global.liveness.initial }} + periodSeconds: {{ $.Values.global.liveness.period }} + {{- if $val.timeoutSeconds }} + timeoutSeconds: {{ $val.timeoutSeconds }} + {{- end }} + + # 볼륨 마운트 + volumeMounts: + - name: app-config + mountPath: /config + readOnly: true + + volumes: + - name: app-config + configMap: + name: {{ $.Values.config.configMapName }} + {{- end }} \ No newline at end of file diff --git a/infra/spot-apps/templates/ingress.yaml b/infra/spot-apps/templates/ingress.yaml new file mode 100644 index 00000000..b6dea980 --- /dev/null +++ b/infra/spot-apps/templates/ingress.yaml @@ -0,0 +1,24 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Values.global.name }}-ingress + annotations: + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + ingressClassName: {{ .Values.ingress.className }} + rules: + # 도메인(Spot, Kafka, Temporal) + {{- range .Values.ingress.subs }} + - host: {{ .name }}.{{ $.Values.domain }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ .serviceName }} + port: + number: 80 + {{- end}} \ No newline at end of file diff --git a/infra/spot-apps/templates/service.yaml b/infra/spot-apps/templates/service.yaml new file mode 100644 index 00000000..b363bb95 --- /dev/null +++ b/infra/spot-apps/templates/service.yaml @@ -0,0 +1,16 @@ +{{- range $key, $val := .Values.apps }} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ $val.name }} + labels: + app: {{ $val.name }} +spec: + type: ClusterIP + selector: + app: {{ $val.name }} + ports: + - port: {{ $val.port }} + targetPort: {{ $val.targetPort | default $val.port }} + {{- end }} \ No newline at end of file diff --git a/infra/spot-apps/values.yaml b/infra/spot-apps/values.yaml new file mode 100644 index 00000000..5a3c9627 --- /dev/null +++ b/infra/spot-apps/values.yaml @@ -0,0 +1,87 @@ +# [1] Ingress 공통 설정 (기본값: AWS ALB) +ingress: + enabled: true + className: "alb" + + annotations: + alb.ingress.kubernetes.io/scheme: internet-facing + alb.ingress.kubernetes.io/target-type: ip + alb.ingress.kubernetes.io/healthcheck-path: /actuator/health + alb.ingress.kubernetes.io/success-codes: "200" # 헬스 체크 성공 코드 + + subs: + - name: www + serviceName: spot-gateway + - name: kafka + serviceName: kafka-ui-svc + - name: temporal + serviceName: temporal-ui-svc + +# 도메인 (AWS) +domain: spotorder.org + +# [2] Deployment 공통 설정 (Global) +global: + name: spot + repository: 322546275072.dkr.ecr.ap-northeast-2.amazonaws.com + imagePullPolicy: Always + replicas: 1 + + # 리소스 제한 + requests: + cpu: "250m" + memory: "512Mi" + limits: + cpu: "800m" + memory: "1Gi" + + # 헬스 체크 + path: /actuator/health + + readiness: + initial: 90 + period: 10 + liveness: + initial: 120 + period: 30 + +# [3] app 목록 +apps: + gateway: + name: spot-gateway + port: 80 + targetPort: 8080 + timeoutSeconds: 5 + failureThreshold: 5 + successThreshold: 1 + + user: + name: spot-user + port: 8081 + + store: + name: spot-store + port: 8083 + + order: + name: spot-order + port: 8082 + + payment: + name: spot-payment + port: 8084 + +# [4] env +env: + activeProfile: "k8s" + loggingConfig: "classpath:logback-spring.xml" + postgres: + - db: POSTGRES_DB + value: "myapp_db" + - user: POSTGRES_USER + value: "admin" + +# [5] config +config: + secretName: spot-secrets + configMapName: spot-app-config \ No newline at end of file diff --git a/infra/spot-apps/values/local-values.yaml b/infra/spot-apps/values/local-values.yaml new file mode 100644 index 00000000..44338ab7 --- /dev/null +++ b/infra/spot-apps/values/local-values.yaml @@ -0,0 +1,11 @@ +# --- Ingress --- +ingress: + className: "nginx" + annotations: { kubernetes.io/ingress.class: nginx } + +# domain +domain: localhost + +# [2] 로컬 환경 Deployment 설정 (Global) +global: + repository: spot-registry.localhost:5111 \ No newline at end of file diff --git a/run_k3d.sh b/run_k3d.sh index 8e4429b1..8e7008b4 100755 --- a/run_k3d.sh +++ b/run_k3d.sh @@ -209,6 +209,20 @@ deploy_all() { log_info "Infrastructure deployed successfully!" + # 5. Apps 배포 (Helm) + log_info "Deploying Apps (Helm)..." + + CHART_PATH="$SCRIPT_DIR/infra/spot-apps" + + helm upgrade --install spot "$CHART_PATH" \ + -n spot \ + -f "$CHART_PATH/values/local-values.yaml" \ + --set global.secretName=spot-secrets \ + --wait \ + --timeout 10m + + log_info "Apps Deployed Successfully!" + log_info "Waiting for monitoring system to be ready..." kubectl wait --for=condition=available deployment/loki-deploy -n monitoring --timeout=180s || true kubectl wait --for=condition=available deployment/grafana-deploy -n monitoring --timeout=180s || true