From e008f174578421da954d932a30be3378e7e91329 Mon Sep 17 00:00:00 2001 From: jungwoo choi Date: Tue, 28 Oct 2025 18:28:36 +0900 Subject: [PATCH] feat: Setup KIND cluster for local Kubernetes development MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created 5-node KIND cluster (1 control-plane + 4 workers) - Configured NodePort mappings for console access (30080, 30081) - Created namespace separation (site11-console, site11-pipeline) - Deployed MongoDB and Redis in KIND cluster - Deployed Console backend and frontend with NodePort services - All 4 pods running successfully and verified with browser test Infrastructure: - k8s/kind-dev-cluster.yaml: 5-node cluster configuration - k8s/kind/console-mongodb-redis.yaml: Database deployments - k8s/kind/console-backend.yaml: Backend with NodePort - k8s/kind/console-frontend.yaml: Frontend with NodePort Management Tools: - scripts/kind-setup.sh: Comprehensive cluster management script - docker-compose.kubernetes.yml: Monitoring helper services Documentation: - KUBERNETES.md: Complete usage guide for developers - docs/KIND_SETUP.md: Detailed KIND setup documentation - docs/PROGRESS.md: Updated with KIND cluster completion Console Services Access: - Frontend: http://localhost:3000 (NodePort 30080) - Backend: http://localhost:8000 (NodePort 30081) ๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- KUBERNETES.md | 339 ++++++++++++++++++++++++ docker-compose.kubernetes.yml | 112 ++++++++ docs/KIND_SETUP.md | 393 ++++++++++++++++++++++++++++ docs/PROGRESS.md | 70 ++++- k8s/kind-dev-cluster.yaml | 71 +++++ k8s/kind/console-backend.yaml | 79 ++++++ k8s/kind/console-frontend.yaml | 65 +++++ k8s/kind/console-mongodb-redis.yaml | 108 ++++++++ scripts/kind-setup.sh | 225 ++++++++++++++++ 9 files changed, 1448 insertions(+), 14 deletions(-) create mode 100644 KUBERNETES.md create mode 100644 docker-compose.kubernetes.yml create mode 100644 docs/KIND_SETUP.md create mode 100644 k8s/kind-dev-cluster.yaml create mode 100644 k8s/kind/console-backend.yaml create mode 100644 k8s/kind/console-frontend.yaml create mode 100644 k8s/kind/console-mongodb-redis.yaml create mode 100755 scripts/kind-setup.sh diff --git a/KUBERNETES.md b/KUBERNETES.md new file mode 100644 index 0000000..8d1c28a --- /dev/null +++ b/KUBERNETES.md @@ -0,0 +1,339 @@ +# Kubernetes Development Environment (KIND) + +Site11 ํ”„๋กœ์ ํŠธ๋Š” KIND (Kubernetes IN Docker)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ์ปฌ Kubernetes ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +## ๋ชฉ์ฐจ +- [์‚ฌ์ „ ์š”๊ตฌ์‚ฌํ•ญ](#์‚ฌ์ „-์š”๊ตฌ์‚ฌํ•ญ) +- [๋น ๋ฅธ ์‹œ์ž‘](#๋น ๋ฅธ-์‹œ์ž‘) +- [๊ด€๋ฆฌ ๋ฐฉ๋ฒ•](#๊ด€๋ฆฌ-๋ฐฉ๋ฒ•) +- [์ ‘์† ์ •๋ณด](#์ ‘์†-์ •๋ณด) +- [๋ฌธ์ œ ํ•ด๊ฒฐ](#๋ฌธ์ œ-ํ•ด๊ฒฐ) + +## ์‚ฌ์ „ ์š”๊ตฌ์‚ฌํ•ญ + +๋‹ค์Œ ๋„๊ตฌ๋“ค์ด ์„ค์น˜๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค: + +```bash +# Docker Desktop +brew install --cask docker + +# KIND +brew install kind + +# kubectl +brew install kubectl +``` + +## ๋น ๋ฅธ ์‹œ์ž‘ + +### ๋ฐฉ๋ฒ• 1: ์Šคํฌ๋ฆฝํŠธ ์‚ฌ์šฉ (๊ถŒ์žฅ) + +```bash +# ์ „์ฒด ํ™˜๊ฒฝ ํ•œ๋ฒˆ์— ์„ค์ • (ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ + ์„œ๋น„์Šค ๋ฐฐํฌ) +./scripts/kind-setup.sh setup + +# ์ƒํƒœ ํ™•์ธ +./scripts/kind-setup.sh status + +# ์ ‘์† ์ •๋ณด ํ™•์ธ +./scripts/kind-setup.sh access +``` + +### ๋ฐฉ๋ฒ• 2: docker-compose ์‚ฌ์šฉ + +```bash +# ํ—ฌํผ ์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘ (๋ชจ๋‹ˆํ„ฐ๋ง ํฌํ•จ) +docker-compose -f docker-compose.kubernetes.yml up -d + +# ๋ชจ๋‹ˆํ„ฐ๋ง ๋กœ๊ทธ ํ™•์ธ +docker-compose -f docker-compose.kubernetes.yml logs -f kind-monitor + +# ํ—ฌํผ ์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€ +docker-compose -f docker-compose.kubernetes.yml down +``` + +**์ฐธ๊ณ **: KIND ํด๋Ÿฌ์Šคํ„ฐ ์ž์ฒด๋Š” ์—ฌ์ „ํžˆ `kind` CLI ๋˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋กœ ๊ด€๋ฆฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. docker-compose๋Š” ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ ๊ด€๋ฆฌ ํ—ฌํผ๋งŒ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. + +### ๋ฐฉ๋ฒ• 3: ์ˆ˜๋™ ์„ค์ • + +```bash +# 1. ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ +kind create cluster --config k8s/kind-dev-cluster.yaml + +# 2. ๋„ค์ž„์ŠคํŽ˜์ด์Šค ์ƒ์„ฑ +kubectl create namespace site11-console +kubectl create namespace site11-pipeline + +# 3. Docker ์ด๋ฏธ์ง€ ๋กœ๋“œ +kind load docker-image yakenator/site11-console-backend:latest --name site11-dev +kind load docker-image yakenator/site11-console-frontend:latest --name site11-dev + +# 4. ์„œ๋น„์Šค ๋ฐฐํฌ +kubectl apply -f k8s/kind/console-mongodb-redis.yaml +kubectl apply -f k8s/kind/console-backend.yaml +kubectl apply -f k8s/kind/console-frontend.yaml + +# 5. ์ƒํƒœ ํ™•์ธ +kubectl get pods -n site11-console +``` + +## ๊ด€๋ฆฌ ๋ฐฉ๋ฒ• + +### ์Šคํฌ๋ฆฝํŠธ ๋ช…๋ น์–ด + +```bash +# ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ +./scripts/kind-setup.sh create + +# ํด๋Ÿฌ์Šคํ„ฐ ์‚ญ์ œ +./scripts/kind-setup.sh delete + +# ๋„ค์ž„์ŠคํŽ˜์ด์Šค ์ƒ์„ฑ +./scripts/kind-setup.sh deploy-namespaces + +# Docker ์ด๋ฏธ์ง€ ๋กœ๋“œ +./scripts/kind-setup.sh load-images + +# Console ์„œ๋น„์Šค ๋ฐฐํฌ +./scripts/kind-setup.sh deploy-console + +# ์ƒํƒœ ํ™•์ธ +./scripts/kind-setup.sh status + +# Pod ๋กœ๊ทธ ํ™•์ธ +./scripts/kind-setup.sh logs site11-console [pod-name] + +# ์ ‘์† ์ •๋ณด ํ‘œ์‹œ +./scripts/kind-setup.sh access +``` + +### kubectl ๋ช…๋ น์–ด + +```bash +# ์ „์ฒด ๋ฆฌ์†Œ์Šค ํ™•์ธ +kubectl get all -n site11-console + +# Pod ์ƒ์„ธ ์ •๋ณด +kubectl describe pod -n site11-console + +# Pod ๋กœ๊ทธ ํ™•์ธ +kubectl logs -n site11-console -f + +# Pod ๋‚ด๋ถ€ ์ ‘์† +kubectl exec -it -n site11-console -- /bin/bash + +# ์„œ๋น„์Šค ํ™•์ธ +kubectl get svc -n site11-console + +# ๋…ธ๋“œ ํ™•์ธ +kubectl get nodes +``` + +## ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ + +### ๋…ธ๋“œ ๊ตฌ์„ฑ (5 ๋…ธ๋“œ) + +- **Control Plane (1๊ฐœ)**: ํด๋Ÿฌ์Šคํ„ฐ ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ + - NodePort ๋งคํ•‘: 30080 โ†’ 3000 (Frontend), 30081 โ†’ 8000 (Backend) + +- **Worker Nodes (4๊ฐœ)**: + - `workload=console`: Console ์„œ๋น„์Šค ์ „์šฉ + - `workload=pipeline-collector`: ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ์„œ๋น„์Šค + - `workload=pipeline-processor`: ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ์„œ๋น„์Šค + - `workload=pipeline-generator`: ์ฝ˜ํ…์ธ  ์ƒ์„ฑ ์„œ๋น„์Šค + +### ๋„ค์ž„์ŠคํŽ˜์ด์Šค + +- `site11-console`: Console ํ”„๋ก ํŠธ์—”๋“œ/๋ฐฑ์—”๋“œ, MongoDB, Redis +- `site11-pipeline`: Pipeline ๊ด€๋ จ ์„œ๋น„์Šค๋“ค + +## ์ ‘์† ์ •๋ณด + +### Console Services + +- **Frontend**: http://localhost:3000 + - NodePort: 30080 + - ์ปจํ…Œ์ด๋„ˆ ํฌํŠธ: 80 + +- **Backend**: http://localhost:8000 + - NodePort: 30081 + - ์ปจํ…Œ์ด๋„ˆ ํฌํŠธ: 8000 + +### ๋‚ด๋ถ€ ์„œ๋น„์Šค (Pod ๋‚ด๋ถ€์—์„œ๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅ) + +- **MongoDB**: `mongodb://mongodb:27017` +- **Redis**: `redis://redis:6379` + +## ๊ฐœ๋ฐœ ์›Œํฌํ”Œ๋กœ์šฐ + +### 1. ์ฝ”๋“œ ๋ณ€๊ฒฝ ํ›„ ๋ฐฐํฌ + +```bash +# 1. Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ +docker build -t yakenator/site11-console-backend:latest \ + -f services/console/backend/Dockerfile \ + services/console/backend + +# 2. KIND ํด๋Ÿฌ์Šคํ„ฐ์— ์ด๋ฏธ์ง€ ๋กœ๋“œ +kind load docker-image yakenator/site11-console-backend:latest --name site11-dev + +# 3. Pod ์žฌ์‹œ์ž‘ +kubectl rollout restart deployment/console-backend -n site11-console + +# 4. ๋ฐฐํฌ ์ƒํƒœ ํ™•์ธ +kubectl rollout status deployment/console-backend -n site11-console +``` + +### 2. ์Šคํฌ๋ฆฝํŠธ๋กœ ๊ฐ„ํŽธํ•˜๊ฒŒ + +```bash +# ์ด๋ฏธ์ง€ ๋นŒ๋“œ ํ›„ ๋กœ๋“œ +./scripts/kind-setup.sh load-images + +# ๋ฐฐํฌ ์žฌ์‹œ์ž‘ +kubectl rollout restart deployment/console-backend -n site11-console +kubectl rollout restart deployment/console-frontend -n site11-console +``` + +### 3. ์ „์ฒด ์žฌ๋ฐฐํฌ + +```bash +# ํด๋Ÿฌ์Šคํ„ฐ ์‚ญ์ œ ํ›„ ์žฌ์ƒ์„ฑ +./scripts/kind-setup.sh delete +./scripts/kind-setup.sh setup +``` + +## ๋ชจ๋‹ˆํ„ฐ๋ง + +### docker-compose ๋ชจ๋‹ˆํ„ฐ๋ง ์‚ฌ์šฉ + +```bash +# ๋ชจ๋‹ˆํ„ฐ๋ง ์‹œ์ž‘ +docker-compose -f docker-compose.kubernetes.yml up -d + +# ์‹ค์‹œ๊ฐ„ ๋กœ๊ทธ ํ™•์ธ (30์ดˆ๋งˆ๋‹ค ์—…๋ฐ์ดํŠธ) +docker-compose -f docker-compose.kubernetes.yml logs -f kind-monitor +``` + +๋ชจ๋‹ˆํ„ฐ๋ง ์ปจํ…Œ์ด๋„ˆ๋Š” ๋‹ค์Œ ์ •๋ณด๋ฅผ 30์ดˆ๋งˆ๋‹ค ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค: +- ๋…ธ๋“œ ์ƒํƒœ +- Console ๋„ค์ž„์ŠคํŽ˜์ด์Šค Pod ์ƒํƒœ +- Pipeline ๋„ค์ž„์ŠคํŽ˜์ด์Šค Pod ์ƒํƒœ + +## ๋ฌธ์ œ ํ•ด๊ฒฐ + +### Pod์ด ์‹œ์ž‘๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ + +```bash +# Pod ์ƒํƒœ ํ™•์ธ +kubectl get pods -n site11-console + +# Pod ์ƒ์„ธ ์ •๋ณด ํ™•์ธ +kubectl describe pod -n site11-console + +# Pod ๋กœ๊ทธ ํ™•์ธ +kubectl logs -n site11-console +``` + +### ์ด๋ฏธ์ง€ Pull ์—๋Ÿฌ + +```bash +# ๋กœ์ปฌ ์ด๋ฏธ์ง€ ํ™•์ธ +docker images | grep site11 + +# ์ด๋ฏธ์ง€๊ฐ€ ์—†์œผ๋ฉด ๋นŒ๋“œ +docker build -t yakenator/site11-console-backend:latest \ + -f services/console/backend/Dockerfile \ + services/console/backend + +# KIND์— ์ด๋ฏธ์ง€ ๋กœ๋“œ +kind load docker-image yakenator/site11-console-backend:latest --name site11-dev +``` + +### NodePort ์ ‘์† ๋ถˆ๊ฐ€ + +```bash +# ์„œ๋น„์Šค ํ™•์ธ +kubectl get svc -n site11-console + +# NodePort ํ™•์ธ (30080, 30081์ด์–ด์•ผ ํ•จ) +kubectl describe svc console-frontend -n site11-console +kubectl describe svc console-backend -n site11-console + +# ํฌํŠธ ํฌ์›Œ๋”ฉ ๋Œ€์•ˆ (๋ฌธ์ œ๊ฐ€ ๊ณ„์†๋˜๋ฉด) +kubectl port-forward svc/console-frontend 3000:3000 -n site11-console +kubectl port-forward svc/console-backend 8000:8000 -n site11-console +``` + +### ํด๋Ÿฌ์Šคํ„ฐ ์™„์ „ ์ดˆ๊ธฐํ™” + +```bash +# KIND ํด๋Ÿฌ์Šคํ„ฐ ์‚ญ์ œ +kind delete cluster --name site11-dev + +# Docker ๋„คํŠธ์›Œํฌ ์ •๋ฆฌ (ํ•„์š”์‹œ) +docker network prune -f + +# ํด๋Ÿฌ์Šคํ„ฐ ์žฌ์ƒ์„ฑ +./scripts/kind-setup.sh setup +``` + +### MongoDB ์—ฐ๊ฒฐ ์‹คํŒจ + +```bash +# MongoDB Pod ํ™•์ธ +kubectl get pod -n site11-console -l app=mongodb + +# MongoDB ๋กœ๊ทธ ํ™•์ธ +kubectl logs -n site11-console -l app=mongodb + +# MongoDB ์„œ๋น„์Šค ํ™•์ธ +kubectl get svc mongodb -n site11-console + +# Pod ๋‚ด์—์„œ ์—ฐ๊ฒฐ ํ…Œ์ŠคํŠธ +kubectl exec -it -n site11-console -- \ + curl mongodb:27017 +``` + +## ์ฐธ๊ณ  ๋ฌธ์„œ + +- [KIND ๊ณต์‹ ๋ฌธ์„œ](https://kind.sigs.k8s.io/) +- [Kubernetes ๊ณต์‹ ๋ฌธ์„œ](https://kubernetes.io/docs/) +- [KIND ์„ค์ • ๊ฐ€์ด๋“œ](./docs/KIND_SETUP.md) + +## ์œ ์šฉํ•œ ํŒ + +### kubectl ์ž๋™์™„์„ฑ ์„ค์ • + +```bash +# Bash +echo 'source <(kubectl completion bash)' >>~/.bashrc + +# Zsh +echo 'source <(kubectl completion zsh)' >>~/.zshrc +``` + +### kubectl ๋‹จ์ถ•์–ด ์„ค์ • + +```bash +# ~/.bashrc ๋˜๋Š” ~/.zshrc์— ์ถ”๊ฐ€ +alias k='kubectl' +alias kgp='kubectl get pods' +alias kgs='kubectl get svc' +alias kgn='kubectl get nodes' +alias kl='kubectl logs' +alias kd='kubectl describe' +``` + +### Context ๋น ๋ฅธ ์ „ํ™˜ + +```bash +# ํ˜„์žฌ context ํ™•์ธ +kubectl config current-context + +# KIND context๋กœ ์ „ํ™˜ +kubectl config use-context kind-site11-dev + +# ๊ธฐ๋ณธ namespace ์„ค์ • +kubectl config set-context --current --namespace=site11-console +``` diff --git a/docker-compose.kubernetes.yml b/docker-compose.kubernetes.yml new file mode 100644 index 0000000..42c6008 --- /dev/null +++ b/docker-compose.kubernetes.yml @@ -0,0 +1,112 @@ +version: '3.8' + +# KIND (Kubernetes IN Docker) ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌ์šฉ docker-compose +# ์‚ฌ์šฉ๋ฒ•: +# ์‹œ์ž‘: docker-compose -f docker-compose.kubernetes.yml up -d +# ์ค‘์ง€: docker-compose -f docker-compose.kubernetes.yml down +# ์žฌ์‹œ์ž‘: docker-compose -f docker-compose.kubernetes.yml restart +# ๋กœ๊ทธ: docker-compose -f docker-compose.kubernetes.yml logs -f + +services: + # KIND ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌ ํ—ฌํผ ์„œ๋น„์Šค + # KIND ํด๋Ÿฌ์Šคํ„ฐ๋Š” docker-compose๋กœ ์ง์ ‘ ์ œ์–ดํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ + # ์ด ํ—ฌํผ ์„œ๋น„์Šค๋ฅผ ํ†ตํ•ด ๊ด€๋ฆฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค + kind-manager: + image: docker/compose:latest + container_name: site11-kind-manager + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ./k8s:/k8s:ro + - ./scripts:/scripts:ro + networks: + - kind + entrypoint: /bin/sh + command: | + -c " + echo '===================================='; + echo 'Site11 KIND Cluster Manager'; + echo '===================================='; + echo ''; + echo 'KIND ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌ ๋ช…๋ น์–ด:'; + echo ' ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ: kind create cluster --config /k8s/kind-dev-cluster.yaml'; + echo ' ํด๋Ÿฌ์Šคํ„ฐ ์‚ญ์ œ: kind delete cluster --name site11-dev'; + echo ' ํด๋Ÿฌ์Šคํ„ฐ ์ƒํƒœ: kubectl cluster-info --context kind-site11-dev'; + echo ' ๋…ธ๋“œ ํ™•์ธ: kubectl get nodes'; + echo ''; + echo 'Services ๋ฐฐํฌ:'; + echo ' ๋„ค์ž„์ŠคํŽ˜์ด์Šค: kubectl create namespace site11-console'; + echo ' Console: kubectl apply -f /k8s/kind/'; + echo ''; + echo 'ํ—ฌํผ ์ปจํ…Œ์ด๋„ˆ๋Š” ๊ณ„์† ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค...'; + tail -f /dev/null + " + restart: unless-stopped + + # Kubectl ๋ช…๋ น์–ด ์‹คํ–‰์„ ์œ„ํ•œ ํ—ฌํผ ์„œ๋น„์Šค + kubectl: + image: bitnami/kubectl:latest + container_name: site11-kubectl + volumes: + - ~/.kube:/root/.kube:ro + - ./k8s:/k8s:ro + networks: + - kind + entrypoint: /bin/bash + command: | + -c " + echo '===================================='; + echo 'Kubectl Helper Container'; + echo '===================================='; + echo ''; + echo 'kubectl ๋ช…๋ น์–ด ์‚ฌ์šฉ ๊ฐ€๋Šฅ'; + echo ' ์˜ˆ์‹œ: docker exec site11-kubectl kubectl get pods -A'; + echo ''; + tail -f /dev/null + " + restart: unless-stopped + + # KIND ํด๋Ÿฌ์Šคํ„ฐ ํ—ฌ์Šค์ฒดํฌ ๋ฐ ๋ชจ๋‹ˆํ„ฐ๋ง + kind-monitor: + image: bitnami/kubectl:latest + container_name: site11-kind-monitor + volumes: + - ~/.kube:/root/.kube:ro + networks: + - kind + entrypoint: /bin/bash + command: | + -c " + while true; do + echo '==== KIND Cluster Status ===='; + kubectl get nodes --context kind-site11-dev 2>/dev/null || echo 'Cluster not running'; + echo ''; + echo '==== Console Namespace Pods ===='; + kubectl get pods -n site11-console --context kind-site11-dev 2>/dev/null || echo 'Namespace not found'; + echo ''; + echo '==== Pipeline Namespace Pods ===='; + kubectl get pods -n site11-pipeline --context kind-site11-dev 2>/dev/null || echo 'Namespace not found'; + echo ''; + sleep 30; + done + " + restart: unless-stopped + +networks: + kind: + name: kind + driver: bridge + +# ์ฐธ๊ณ : +# 1. KIND ํด๋Ÿฌ์Šคํ„ฐ ์ž์ฒด๋Š” docker-compose๋กœ ์ง์ ‘ ์ œ์–ด๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค +# 2. ์ด ํŒŒ์ผ์€ KIND ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ ํ—ฌํผ ์ปจํ…Œ์ด๋„ˆ๋“ค์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค +# 3. ์‹ค์ œ ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ/์‚ญ์ œ๋Š” kind CLI๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค +# +# KIND ํด๋Ÿฌ์Šคํ„ฐ ๋ผ์ดํ”„์‚ฌ์ดํด: +# ์ƒ์„ฑ: kind create cluster --config k8s/kind-dev-cluster.yaml +# ์‚ญ์ œ: kind delete cluster --name site11-dev +# ๋ชฉ๋ก: kind get clusters +# +# docker-compose ๋ช…๋ น์–ด: +# ํ—ฌํผ ์‹œ์ž‘: docker-compose -f docker-compose.kubernetes.yml up -d +# ํ—ฌํผ ์ค‘์ง€: docker-compose -f docker-compose.kubernetes.yml down +# ๋กœ๊ทธ ํ™•์ธ: docker-compose -f docker-compose.kubernetes.yml logs -f kind-monitor diff --git a/docs/KIND_SETUP.md b/docs/KIND_SETUP.md new file mode 100644 index 0000000..cdb49d0 --- /dev/null +++ b/docs/KIND_SETUP.md @@ -0,0 +1,393 @@ +# KIND (Kubernetes IN Docker) ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ค์ • + +## ๊ฐœ์š” +Docker Desktop์˜ Kubernetes ๋Œ€์‹  KIND๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +### KIND ์„ ํƒ ์ด์œ  +1. **๋…๋ฆฝ์„ฑ**: Docker Desktop Kubernetes์™€ ๋ณ„๋„๋กœ ๊ด€๋ฆฌ +2. **์žฌํ˜„์„ฑ**: ์„ค์ • ํŒŒ์ผ๋กœ ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ ๊ด€๋ฆฌ +3. **๋ฉ€ํ‹ฐ ๋…ธ๋“œ**: ์‹ค์ œ ํ”„๋กœ๋•์…˜๊ณผ ์œ ์‚ฌํ•œ ๋ฉ€ํ‹ฐ ๋…ธ๋“œ ํ™˜๊ฒฝ +4. **๋น ๋ฅธ ์žฌ์‹œ์ž‘**: ํ•„์š”์‹œ ํด๋Ÿฌ์Šคํ„ฐ ์‚ญ์ œ/์žฌ์ƒ์„ฑ ์šฉ์ด +5. **๋ฆฌ์†Œ์Šค ๊ด€๋ฆฌ**: ๋…ธ๋“œ๋ณ„ ๋ฆฌ์†Œ์Šค ํ• ๋‹น ๊ฐ€๋Šฅ + +## ์‚ฌ์ „ ์š”๊ตฌ์‚ฌํ•ญ + +### 1. KIND ์„ค์น˜ +```bash +# macOS (Homebrew) +brew install kind + +# ๋˜๋Š” ์ง์ ‘ ๋‹ค์šด๋กœ๋“œ +curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-darwin-amd64 +chmod +x ./kind +sudo mv ./kind /usr/local/bin/kind + +# ์„ค์น˜ ํ™•์ธ +kind version +``` + +### 2. kubectl ์„ค์น˜ +```bash +# macOS (Homebrew) +brew install kubectl + +# ์„ค์น˜ ํ™•์ธ +kubectl version --client +``` + +### 3. Docker ์‹คํ–‰ ํ™•์ธ +```bash +docker ps +# Docker๊ฐ€ ์‹คํ–‰ ์ค‘์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค +``` + +## ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ + +### 5-Node ํด๋Ÿฌ์Šคํ„ฐ ์„ค์ • ํŒŒ์ผ +ํŒŒ์ผ ์œ„์น˜: `k8s/kind-dev-cluster.yaml` + +```yaml +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +name: site11-dev + +# ๋…ธ๋“œ ๊ตฌ์„ฑ +nodes: + # Control Plane (๋งˆ์Šคํ„ฐ ๋…ธ๋“œ) + - role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "node-type=control-plane" + extraPortMappings: + # Console Frontend + - containerPort: 30080 + hostPort: 3000 + protocol: TCP + # Console Backend + - containerPort: 30081 + hostPort: 8000 + protocol: TCP + + # Worker Node 1 (Console ์„œ๋น„์Šค์šฉ) + - role: worker + labels: + workload: console + node-type: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "workload=console" + + # Worker Node 2 (Pipeline ์„œ๋น„์Šค์šฉ - ์ˆ˜์ง‘) + - role: worker + labels: + workload: pipeline-collector + node-type: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "workload=pipeline-collector" + + # Worker Node 3 (Pipeline ์„œ๋น„์Šค์šฉ - ์ฒ˜๋ฆฌ) + - role: worker + labels: + workload: pipeline-processor + node-type: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "workload=pipeline-processor" + + # Worker Node 4 (Pipeline ์„œ๋น„์Šค์šฉ - ์ƒ์„ฑ) + - role: worker + labels: + workload: pipeline-generator + node-type: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "workload=pipeline-generator" +``` + +### ๋…ธ๋“œ ์—ญํ•  ๋ถ„๋‹ด +- **Control Plane**: ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌ, API ์„œ๋ฒ„ +- **Worker 1 (console)**: Console Backend, Console Frontend +- **Worker 2 (pipeline-collector)**: RSS Collector, Google Search +- **Worker 3 (pipeline-processor)**: Translator +- **Worker 4 (pipeline-generator)**: AI Article Generator, Image Generator + +## ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌ ๋ช…๋ น์–ด + +### ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ +```bash +# KIND ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ +kind create cluster --config k8s/kind-dev-cluster.yaml + +# ์ƒ์„ฑ ํ™•์ธ +kubectl cluster-info --context kind-site11-dev +kubectl get nodes +``` + +### ํด๋Ÿฌ์Šคํ„ฐ ์‚ญ์ œ +```bash +# ํด๋Ÿฌ์Šคํ„ฐ ์‚ญ์ œ +kind delete cluster --name site11-dev + +# ๋ชจ๋“  KIND ํด๋Ÿฌ์Šคํ„ฐ ํ™•์ธ +kind get clusters +``` + +### ์ปจํ…์ŠคํŠธ ์ „ํ™˜ +```bash +# KIND ํด๋Ÿฌ์Šคํ„ฐ๋กœ ์ „ํ™˜ +kubectl config use-context kind-site11-dev + +# ํ˜„์žฌ ์ปจํ…์ŠคํŠธ ํ™•์ธ +kubectl config current-context + +# ๋ชจ๋“  ์ปจํ…์ŠคํŠธ ๋ณด๊ธฐ +kubectl config get-contexts +``` + +## ์„œ๋น„์Šค ๋ฐฐํฌ + +### 1. Namespace ์ƒ์„ฑ +```bash +# Console namespace +kubectl create namespace site11-console + +# Pipeline namespace +kubectl create namespace site11-pipeline +``` + +### 2. ConfigMap ๋ฐ Secret ๋ฐฐํฌ +```bash +# Pipeline ์„ค์ • +kubectl apply -f k8s/pipeline/configmap-dockerhub.yaml +``` + +### 3. ์„œ๋น„์Šค ๋ฐฐํฌ +```bash +# Console ์„œ๋น„์Šค +kubectl apply -f k8s/console/console-backend.yaml +kubectl apply -f k8s/console/console-frontend.yaml + +# Pipeline ์„œ๋น„์Šค +kubectl apply -f k8s/pipeline/rss-collector-dockerhub.yaml +kubectl apply -f k8s/pipeline/google-search-dockerhub.yaml +kubectl apply -f k8s/pipeline/translator-dockerhub.yaml +kubectl apply -f k8s/pipeline/ai-article-generator-dockerhub.yaml +kubectl apply -f k8s/pipeline/image-generator-dockerhub.yaml +``` + +### 4. ๋ฐฐํฌ ํ™•์ธ +```bash +# Pod ์ƒํƒœ ํ™•์ธ +kubectl -n site11-console get pods -o wide +kubectl -n site11-pipeline get pods -o wide + +# Service ํ™•์ธ +kubectl -n site11-console get svc +kubectl -n site11-pipeline get svc + +# ๋…ธ๋“œ๋ณ„ Pod ๋ถ„ํฌ ํ™•์ธ +kubectl get pods -A -o wide +``` + +## ์ ‘์† ๋ฐฉ๋ฒ• + +### NodePort ๋ฐฉ์‹ (๊ถŒ์žฅ) +KIND ํด๋Ÿฌ์Šคํ„ฐ๋Š” NodePort๋ฅผ ํ†ตํ•ด ์„œ๋น„์Šค๋ฅผ ๋…ธ์ถœํ•ฉ๋‹ˆ๋‹ค. + +```yaml +# Console Frontend Service ์˜ˆ์‹œ +apiVersion: v1 +kind: Service +metadata: + name: console-frontend +spec: + type: NodePort + ports: + - port: 80 + targetPort: 80 + nodePort: 30080 # http://localhost:3000 + selector: + app: console-frontend +``` + +์ ‘์†: +- Console Frontend: http://localhost:3000 +- Console Backend: http://localhost:8000 + +### Port Forward ๋ฐฉ์‹ (๋Œ€์•ˆ) +```bash +# Console Backend +kubectl -n site11-console port-forward svc/console-backend 8000:8000 & + +# Console Frontend +kubectl -n site11-console port-forward svc/console-frontend 3000:80 & +``` + +## ๋ชจ๋‹ˆํ„ฐ๋ง + +### ํด๋Ÿฌ์Šคํ„ฐ ์ƒํƒœ +```bash +# ๋…ธ๋“œ ์ƒํƒœ +kubectl get nodes + +# ์ „์ฒด ๋ฆฌ์†Œ์Šค +kubectl get all -A + +# ํŠน์ • ๋…ธ๋“œ์˜ Pod +kubectl get pods -A -o wide | grep +``` + +### ๋กœ๊ทธ ํ™•์ธ +```bash +# Pod ๋กœ๊ทธ +kubectl -n site11-console logs + +# ์‹ค์‹œ๊ฐ„ ๋กœ๊ทธ +kubectl -n site11-console logs -f + +# ์ด์ „ ์ปจํ…Œ์ด๋„ˆ ๋กœ๊ทธ +kubectl -n site11-console logs --previous +``` + +### ๋ฆฌ์†Œ์Šค ์‚ฌ์šฉ๋Ÿ‰ +```bash +# ๋…ธ๋“œ ๋ฆฌ์†Œ์Šค +kubectl top nodes + +# Pod ๋ฆฌ์†Œ์Šค +kubectl top pods -A +``` + +## ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ… + +### ์ด๋ฏธ์ง€ ๋กœ๋“œ ๋ฌธ์ œ +KIND๋Š” ๋กœ์ปฌ ์ด๋ฏธ์ง€๋ฅผ ์ž๋™์œผ๋กœ ๋กœ๋“œํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +```bash +# ๋กœ์ปฌ ์ด๋ฏธ์ง€๋ฅผ KIND๋กœ ๋กœ๋“œ +kind load docker-image yakenator/site11-console-backend:latest --name site11-dev +kind load docker-image yakenator/site11-console-frontend:latest --name site11-dev + +# ๋˜๋Š” imagePullPolicy: Always ์‚ฌ์šฉ (Docker Hub์—์„œ ์ž๋™ pull) +``` + +### Pod๊ฐ€ ์‹œ์ž‘ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ +```bash +# Pod ์ƒํƒœ ํ™•์ธ +kubectl -n site11-console describe pod + +# ์ด๋ฒคํŠธ ํ™•์ธ +kubectl -n site11-console get events --sort-by='.lastTimestamp' +``` + +### ๋„คํŠธ์›Œํฌ ๋ฌธ์ œ +```bash +# Service endpoint ํ™•์ธ +kubectl -n site11-console get endpoints + +# DNS ํ…Œ์ŠคํŠธ +kubectl run -it --rm debug --image=busybox --restart=Never -- nslookup console-backend.site11-console.svc.cluster.local +``` + +## ๊ฐœ๋ฐœ ์›Œํฌํ”Œ๋กœ์šฐ + +### 1. ์ฝ”๋“œ ๋ณ€๊ฒฝ ํ›„ ์žฌ๋ฐฐํฌ +```bash +# Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ +docker build -t yakenator/site11-console-backend:latest -f services/console/backend/Dockerfile services/console/backend + +# Docker Hub์— ํ‘ธ์‹œ +docker push yakenator/site11-console-backend:latest + +# Pod ์žฌ์‹œ์ž‘ (์ƒˆ ์ด๋ฏธ์ง€ pull) +kubectl -n site11-console rollout restart deployment console-backend + +# ๋˜๋Š” Pod ์‚ญ์ œ (์ž๋™ ์žฌ์ƒ์„ฑ) +kubectl -n site11-console delete pod -l app=console-backend +``` + +### 2. ๋กœ์ปฌ ๊ฐœ๋ฐœ (๋น ๋ฅธ ํ…Œ์ŠคํŠธ) +```bash +# ๋กœ์ปฌ์—์„œ ์„œ๋น„์Šค ์‹คํ–‰ +cd services/console/backend +uvicorn app.main:app --reload --port 8000 + +# KIND ํด๋Ÿฌ์Šคํ„ฐ์˜ MongoDB ์ ‘์† +kubectl -n site11-console port-forward svc/mongodb 27017:27017 +``` + +### 3. ํด๋Ÿฌ์Šคํ„ฐ ๋ฆฌ์…‹ +```bash +# ์ „์ฒด ์žฌ์ƒ์„ฑ +kind delete cluster --name site11-dev +kind create cluster --config k8s/kind-dev-cluster.yaml + +# ์„œ๋น„์Šค ์žฌ๋ฐฐํฌ +kubectl apply -f k8s/console/ +kubectl apply -f k8s/pipeline/ +``` + +## ์„ฑ๋Šฅ ์ตœ์ ํ™” + +### ๋…ธ๋“œ ๋ฆฌ์†Œ์Šค ์ œํ•œ (์„ ํƒ์‚ฌํ•ญ) +```yaml +nodes: + - role: worker + extraMounts: + - hostPath: /path/to/data + containerPath: /data + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + max-pods: "50" + cpu-manager-policy: "static" +``` + +### ์ด๋ฏธ์ง€ Pull ์ •์ฑ… +```yaml +# Deployment์—์„œ ์„ค์ • +spec: + template: + spec: + containers: + - name: console-backend + image: yakenator/site11-console-backend:latest + imagePullPolicy: Always # ํ•ญ์ƒ ์ตœ์‹  ์ด๋ฏธ์ง€ +``` + +## ๋ฐฑ์—… ๋ฐ ๋ณต์› + +### ํด๋Ÿฌ์Šคํ„ฐ ์„ค์ • ๋ฐฑ์—… +```bash +# ํ˜„์žฌ ๋ฆฌ์†Œ์Šค ๋ฐฑ์—… +kubectl get all -A -o yaml > backup-$(date +%Y%m%d).yaml +``` + +### ๋ณต์› +```bash +# ๋ฐฑ์—…์—์„œ ๋ณต์› +kubectl apply -f backup-20251028.yaml +``` + +## ์ฐธ๊ณ  ์ž๋ฃŒ +- KIND ๊ณต์‹ ๋ฌธ์„œ: https://kind.sigs.k8s.io/ +- Kubernetes ๊ณต์‹ ๋ฌธ์„œ: https://kubernetes.io/docs/ +- KIND GitHub: https://github.com/kubernetes-sigs/kind diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index d266013..66d69d8 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -6,7 +6,7 @@ ## Current Status - **Date Started**: 2025-09-09 - **Last Updated**: 2025-10-28 -- **Current Phase**: Phase 2 In Progress ๐Ÿ”„ (Service Management CRUD - Backend Complete) +- **Current Phase**: KIND Cluster Setup Complete โœ… - **Next Action**: Phase 2 - Frontend UI Implementation ## Completed Checkpoints @@ -130,6 +130,40 @@ All authentication endpoints tested and working: - `/services/console/frontend/src/types/service.ts` - TypeScript types - `/services/console/frontend/src/api/service.ts` - API client +### KIND Cluster Setup (Local Development Environment) โœ… +**Completed Date**: 2025-10-28 + +#### Infrastructure Setup +โœ… KIND (Kubernetes IN Docker) 5-node cluster +โœ… Cluster configuration with role-based workers +โœ… NodePort mappings for console access (30080, 30081) +โœ… Namespace separation (site11-console, site11-pipeline) +โœ… MongoDB and Redis deployed in cluster +โœ… Console backend and frontend deployed with NodePort services +โœ… All 4 pods running successfully + +#### Management Tools +โœ… `kind-setup.sh` script for cluster management +โœ… `docker-compose.kubernetes.yml` for monitoring +โœ… Comprehensive documentation (KUBERNETES.md, KIND_SETUP.md) + +#### Kubernetes Resources Created +- **Cluster Config**: `/k8s/kind-dev-cluster.yaml` +- **Console MongoDB/Redis**: `/k8s/kind/console-mongodb-redis.yaml` +- **Console Backend**: `/k8s/kind/console-backend.yaml` +- **Console Frontend**: `/k8s/kind/console-frontend.yaml` +- **Management Script**: `/scripts/kind-setup.sh` +- **Docker Compose**: `/docker-compose.kubernetes.yml` +- **Documentation**: `/KUBERNETES.md` + +#### Verification Results +โœ… Cluster created with 5 nodes (all Ready) +โœ… Console namespace with 4 running pods +โœ… NodePort services accessible (3000, 8000) +โœ… Frontend login/register tested successfully +โœ… Backend API health check passed +โœ… Authentication system working in KIND cluster + ### Earlier Checkpoints โœ… Project structure planning (CLAUDE.md) โœ… Implementation plan created (docs/PLAN.md) @@ -151,27 +185,35 @@ All authentication endpoints tested and working: ## Deployment Status -### Kubernetes Cluster: site11-pipeline +### KIND Cluster: site11-dev โœ… +**Cluster Created**: 2025-10-28 +**Nodes**: 5 (1 control-plane + 4 workers) + ```bash -# Backend -kubectl -n site11-pipeline get pods -l app=console-backend -# Status: 2/2 Running +# Console Namespace +kubectl -n site11-console get pods +# Status: 4/4 Running (mongodb, redis, console-backend, console-frontend) -# Frontend -kubectl -n site11-pipeline get pods -l app=console-frontend -# Status: 2/2 Running +# Cluster Status +./scripts/kind-setup.sh status -# Port Forwarding (for testing) -kubectl -n site11-pipeline port-forward svc/console-backend 8000:8000 -kubectl -n site11-pipeline port-forward svc/console-frontend 3000:80 +# Management +./scripts/kind-setup.sh {create|delete|deploy-console|status|logs|access|setup} ``` -### Access URLs -- Frontend: http://localhost:3000 (via port-forward) -- Backend API: http://localhost:8000 (via port-forward) +### Access URLs (NodePort) +- Frontend: http://localhost:3000 (NodePort 30080) +- Backend API: http://localhost:8000 (NodePort 30081) - Backend Health: http://localhost:8000/health - API Docs: http://localhost:8000/docs +### Monitoring +```bash +# Start monitoring +docker-compose -f docker-compose.kubernetes.yml up -d +docker-compose -f docker-compose.kubernetes.yml logs -f kind-monitor +``` + ## Next Immediate Steps (Phase 2) ### Service Management CRUD diff --git a/k8s/kind-dev-cluster.yaml b/k8s/kind-dev-cluster.yaml new file mode 100644 index 0000000..b1312cf --- /dev/null +++ b/k8s/kind-dev-cluster.yaml @@ -0,0 +1,71 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +name: site11-dev + +# ๋…ธ๋“œ ๊ตฌ์„ฑ (1 Control Plane + 4 Workers = 5 Nodes) +nodes: + # Control Plane (๋งˆ์Šคํ„ฐ ๋…ธ๋“œ) + - role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "node-type=control-plane" + extraPortMappings: + # Console Frontend + - containerPort: 30080 + hostPort: 3000 + protocol: TCP + # Console Backend + - containerPort: 30081 + hostPort: 8000 + protocol: TCP + + # Worker Node 1 (Console ์„œ๋น„์Šค์šฉ) + - role: worker + labels: + workload: console + node-type: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "workload=console" + + # Worker Node 2 (Pipeline ์„œ๋น„์Šค์šฉ - ์ˆ˜์ง‘) + - role: worker + labels: + workload: pipeline-collector + node-type: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "workload=pipeline-collector" + + # Worker Node 3 (Pipeline ์„œ๋น„์Šค์šฉ - ์ฒ˜๋ฆฌ) + - role: worker + labels: + workload: pipeline-processor + node-type: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "workload=pipeline-processor" + + # Worker Node 4 (Pipeline ์„œ๋น„์Šค์šฉ - ์ƒ์„ฑ) + - role: worker + labels: + workload: pipeline-generator + node-type: worker + kubeadmConfigPatches: + - | + kind: JoinConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "workload=pipeline-generator" diff --git a/k8s/kind/console-backend.yaml b/k8s/kind/console-backend.yaml new file mode 100644 index 0000000..3cad08b --- /dev/null +++ b/k8s/kind/console-backend.yaml @@ -0,0 +1,79 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: console-backend + namespace: site11-console + labels: + app: console-backend +spec: + replicas: 1 + selector: + matchLabels: + app: console-backend + template: + metadata: + labels: + app: console-backend + spec: + nodeSelector: + workload: console + containers: + - name: console-backend + image: yakenator/site11-console-backend:latest + imagePullPolicy: IfNotPresent + ports: + - containerPort: 8000 + protocol: TCP + env: + - name: ENV + value: "development" + - name: DEBUG + value: "true" + - name: MONGODB_URL + value: "mongodb://mongodb:27017" + - name: DB_NAME + value: "console_db" + - name: REDIS_URL + value: "redis://redis:6379" + - name: JWT_SECRET_KEY + value: "dev-secret-key-please-change-in-production" + - name: JWT_ALGORITHM + value: "HS256" + - name: ACCESS_TOKEN_EXPIRE_MINUTES + value: "30" + resources: + requests: + memory: "256Mi" + cpu: "100m" + limits: + memory: "512Mi" + cpu: "500m" + readinessProbe: + httpGet: + path: /health + port: 8000 + initialDelaySeconds: 10 + periodSeconds: 5 + livenessProbe: + httpGet: + path: /health + port: 8000 + initialDelaySeconds: 30 + periodSeconds: 10 +--- +apiVersion: v1 +kind: Service +metadata: + name: console-backend + namespace: site11-console + labels: + app: console-backend +spec: + type: NodePort + selector: + app: console-backend + ports: + - port: 8000 + targetPort: 8000 + nodePort: 30081 + protocol: TCP diff --git a/k8s/kind/console-frontend.yaml b/k8s/kind/console-frontend.yaml new file mode 100644 index 0000000..58a74eb --- /dev/null +++ b/k8s/kind/console-frontend.yaml @@ -0,0 +1,65 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: console-frontend + namespace: site11-console + labels: + app: console-frontend +spec: + replicas: 1 + selector: + matchLabels: + app: console-frontend + template: + metadata: + labels: + app: console-frontend + spec: + nodeSelector: + workload: console + containers: + - name: console-frontend + image: yakenator/site11-console-frontend:latest + imagePullPolicy: IfNotPresent + ports: + - containerPort: 80 + protocol: TCP + env: + - name: VITE_API_URL + value: "http://localhost:8000" + resources: + requests: + memory: "128Mi" + cpu: "50m" + limits: + memory: "256Mi" + cpu: "200m" + readinessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 5 + periodSeconds: 5 + livenessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 15 + periodSeconds: 10 +--- +apiVersion: v1 +kind: Service +metadata: + name: console-frontend + namespace: site11-console + labels: + app: console-frontend +spec: + type: NodePort + selector: + app: console-frontend + ports: + - port: 3000 + targetPort: 80 + nodePort: 30080 + protocol: TCP diff --git a/k8s/kind/console-mongodb-redis.yaml b/k8s/kind/console-mongodb-redis.yaml new file mode 100644 index 0000000..46589ba --- /dev/null +++ b/k8s/kind/console-mongodb-redis.yaml @@ -0,0 +1,108 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mongodb + namespace: site11-console + labels: + app: mongodb +spec: + replicas: 1 + selector: + matchLabels: + app: mongodb + template: + metadata: + labels: + app: mongodb + spec: + containers: + - name: mongodb + image: mongo:7.0 + ports: + - containerPort: 27017 + protocol: TCP + env: + - name: MONGO_INITDB_DATABASE + value: "console_db" + resources: + requests: + memory: "512Mi" + cpu: "250m" + limits: + memory: "1Gi" + cpu: "500m" + volumeMounts: + - name: mongodb-data + mountPath: /data/db + volumes: + - name: mongodb-data + emptyDir: {} +--- +apiVersion: v1 +kind: Service +metadata: + name: mongodb + namespace: site11-console + labels: + app: mongodb +spec: + type: ClusterIP + selector: + app: mongodb + ports: + - port: 27017 + targetPort: 27017 + protocol: TCP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis + namespace: site11-console + labels: + app: redis +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + labels: + app: redis + spec: + containers: + - name: redis + image: redis:7-alpine + ports: + - containerPort: 6379 + protocol: TCP + resources: + requests: + memory: "128Mi" + cpu: "100m" + limits: + memory: "256Mi" + cpu: "200m" + volumeMounts: + - name: redis-data + mountPath: /data + volumes: + - name: redis-data + emptyDir: {} +--- +apiVersion: v1 +kind: Service +metadata: + name: redis + namespace: site11-console + labels: + app: redis +spec: + type: ClusterIP + selector: + app: redis + ports: + - port: 6379 + targetPort: 6379 + protocol: TCP diff --git a/scripts/kind-setup.sh b/scripts/kind-setup.sh new file mode 100755 index 0000000..9b1c9c7 --- /dev/null +++ b/scripts/kind-setup.sh @@ -0,0 +1,225 @@ +#!/bin/bash + +# Site11 KIND Cluster Setup Script +# This script manages the KIND (Kubernetes IN Docker) development cluster + +set -e + +CLUSTER_NAME="site11-dev" +CONFIG_FILE="k8s/kind-dev-cluster.yaml" +K8S_DIR="k8s/kind" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo -e "${GREEN}=====================================${NC}" +echo -e "${GREEN}Site11 KIND Cluster Manager${NC}" +echo -e "${GREEN}=====================================${NC}" +echo "" + +# Check if KIND is installed +if ! command -v kind &> /dev/null; then + echo -e "${RED}ERROR: kind is not installed${NC}" + echo "Please install KIND: https://kind.sigs.k8s.io/docs/user/quick-start/#installation" + exit 1 +fi + +# Check if kubectl is installed +if ! command -v kubectl &> /dev/null; then + echo -e "${RED}ERROR: kubectl is not installed${NC}" + echo "Please install kubectl: https://kubernetes.io/docs/tasks/tools/" + exit 1 +fi + +# Function to create cluster +create_cluster() { + echo -e "${YELLOW}Creating KIND cluster: $CLUSTER_NAME${NC}" + + if kind get clusters | grep -q "^$CLUSTER_NAME$"; then + echo -e "${YELLOW}Cluster $CLUSTER_NAME already exists${NC}" + read -p "Do you want to delete and recreate? (y/N): " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + delete_cluster + else + echo "Skipping cluster creation" + return + fi + fi + + kind create cluster --config "$CONFIG_FILE" + echo -e "${GREEN}โœ… Cluster created successfully${NC}" + + # Wait for cluster to be ready + echo "Waiting for cluster to be ready..." + kubectl wait --for=condition=Ready nodes --all --timeout=120s + + echo -e "${GREEN}โœ… All nodes are ready${NC}" +} + +# Function to delete cluster +delete_cluster() { + echo -e "${YELLOW}Deleting KIND cluster: $CLUSTER_NAME${NC}" + kind delete cluster --name "$CLUSTER_NAME" + echo -e "${GREEN}โœ… Cluster deleted${NC}" +} + +# Function to deploy namespaces +deploy_namespaces() { + echo -e "${YELLOW}Creating namespaces${NC}" + kubectl create namespace site11-console --dry-run=client -o yaml | kubectl apply -f - + kubectl create namespace site11-pipeline --dry-run=client -o yaml | kubectl apply -f - + echo -e "${GREEN}โœ… Namespaces created${NC}" +} + +# Function to load images +load_images() { + echo -e "${YELLOW}Loading Docker images into KIND cluster${NC}" + + images=( + "yakenator/site11-console-backend:latest" + "yakenator/site11-console-frontend:latest" + ) + + for image in "${images[@]}"; do + echo "Loading $image..." + if docker image inspect "$image" &> /dev/null; then + kind load docker-image "$image" --name "$CLUSTER_NAME" + else + echo -e "${YELLOW}Warning: Image $image not found locally, skipping${NC}" + fi + done + + echo -e "${GREEN}โœ… Images loaded${NC}" +} + +# Function to deploy console services +deploy_console() { + echo -e "${YELLOW}Deploying Console services${NC}" + + # Deploy in order: databases first, then applications + kubectl apply -f "$K8S_DIR/console-mongodb-redis.yaml" + echo "Waiting for databases to be ready..." + sleep 5 + + kubectl apply -f "$K8S_DIR/console-backend.yaml" + kubectl apply -f "$K8S_DIR/console-frontend.yaml" + + echo -e "${GREEN}โœ… Console services deployed${NC}" +} + +# Function to check cluster status +status() { + echo -e "${YELLOW}Cluster Status${NC}" + echo "" + + if ! kind get clusters | grep -q "^$CLUSTER_NAME$"; then + echo -e "${RED}Cluster $CLUSTER_NAME does not exist${NC}" + return 1 + fi + + echo "=== Nodes ===" + kubectl get nodes + echo "" + + echo "=== Console Namespace Pods ===" + kubectl get pods -n site11-console -o wide + echo "" + + echo "=== Console Services ===" + kubectl get svc -n site11-console + echo "" + + echo "=== Pipeline Namespace Pods ===" + kubectl get pods -n site11-pipeline -o wide 2>/dev/null || echo "No pods found" + echo "" +} + +# Function to show logs +logs() { + namespace=${1:-site11-console} + pod_name=${2:-} + + if [ -z "$pod_name" ]; then + echo "Available pods in namespace $namespace:" + kubectl get pods -n "$namespace" --no-headers | awk '{print $1}' + echo "" + echo "Usage: $0 logs [namespace] [pod-name]" + return + fi + + kubectl logs -n "$namespace" "$pod_name" -f +} + +# Function to access services +access() { + echo -e "${GREEN}Console Services Access Information${NC}" + echo "" + echo "Frontend: http://localhost:3000 (NodePort 30080)" + echo "Backend: http://localhost:8000 (NodePort 30081)" + echo "" + echo "These services are accessible because they use NodePort type" + echo "and are mapped in the KIND cluster configuration." +} + +# Function to setup everything +setup() { + echo -e "${GREEN}Setting up complete KIND development environment${NC}" + create_cluster + deploy_namespaces + load_images + deploy_console + status + access + echo -e "${GREEN}โœ… Setup complete!${NC}" +} + +# Main script logic +case "${1:-}" in + create) + create_cluster + ;; + delete) + delete_cluster + ;; + deploy-namespaces) + deploy_namespaces + ;; + load-images) + load_images + ;; + deploy-console) + deploy_console + ;; + status) + status + ;; + logs) + logs "$2" "$3" + ;; + access) + access + ;; + setup) + setup + ;; + *) + echo "Usage: $0 {create|delete|deploy-namespaces|load-images|deploy-console|status|logs|access|setup}" + echo "" + echo "Commands:" + echo " create - Create KIND cluster" + echo " delete - Delete KIND cluster" + echo " deploy-namespaces - Create namespaces" + echo " load-images - Load Docker images into cluster" + echo " deploy-console - Deploy console services" + echo " status - Show cluster status" + echo " logs [ns] [pod] - Show pod logs" + echo " access - Show service access information" + echo " setup - Complete setup (create + deploy everything)" + echo "" + exit 1 + ;; +esac