반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
Tags
- 분석
- elasticsearch
- 유니티
- docker
- 투자
- API
- Linux
- 바보
- MSSQL
- unity
- MySQL
- build
- LLM
- 구글
- Python
- 주식
- JS
- AWS
- gemini
- nodejs
- error
- Kibana
- app
- JavaScript
- Windows
- FLUTTER
- ChatGPT
- Ai
- 설정
Archives
- Today
- Total
가끔 보자, 하늘.
내 PC에서 k8s 구축 연습해보기 본문
반응형
k8s 구축을 연습할 수 있게 내용 정리를 시켜봤습니다. AI에서 시켜봐도 되는 세상이긴 하지만 간단하니 직접 구축하면서 경험을 먼저 해보시면 이해하는데 더 도움이 될겁니다. 최소한의 리소스로 실행해 볼 수 있게 했으니 여유가 있다면 좀 더 늘려보시는 것도 좋을 듯 하네요. :)
테스트 용 yaml 파일은 아래 첨부했습니다. 다운로드해서 사용하시면 됩니다.
구축될 인프라 구조는 이 링크 에서 확인 가능합니다. ( 인프라 설계 툴 : loom , github)
macOS + Podman + kind 로컬 구축 가이드
환경
- macOS (Apple Silicon / arm64)
- Podman 5.7.0
- Podman machine: 4 CPU, 3.7GB RAM, 9GB Disk
- 디스크 : 5GB 이내
1단계: kind + kubectl 설치
brew install kind kubectl
설치 확인:
kind version
kubectl version --client
2단계: kind 클러스터 생성
KIND_EXPERIMENTAL_PROVIDER=podman kind create cluster --name dev-infra
생성 확인:
kubectl cluster-info
kubectl get nodes
기대 결과:
NAME STATUS ROLES AGE VERSION
dev-infra-control-plane Ready control-plane ... v1.x.x
3단계: Namespace 생성
kubectl apply -f 00-namespace/namespace.yaml
kubectl get namespace dev-infra
4단계: Secrets 생성
kubectl apply -f 01-secrets/postgres-secret.yaml
kubectl apply -f 01-secrets/minio-secret.yaml
kubectl apply -f 01-secrets/redis-secret.yaml
kubectl get secrets -n dev-infra
5단계: PVC 생성
kubectl apply -f 02-storage/postgres-pvc.yaml
kubectl apply -f 02-storage/minio-pvc.yaml
kubectl get pvc -n dev-infra
6단계: PostgreSQL 배포
kubectl apply -f 03-postgres/deployment.yaml
kubectl apply -f 03-postgres/service.yaml
# 기동 대기 (최대 120초)
kubectl wait --for=condition=ready pod -l app=postgres -n dev-infra --timeout=120s
# 확인
kubectl get pods -n dev-infra -l app=postgres
kubectl logs -n dev-infra -l app=postgres --tail=5
접속 테스트:
kubectl run pg-test --rm -it --restart=Never -n dev-infra \
--image=postgres:16-alpine -- \
psql -h postgres-svc -U devuser -d devdb -c "SELECT version();"
# 비밀번호: devpass1234!
7단계: Redis 배포
kubectl apply -f 04-redis/deployment.yaml
kubectl apply -f 04-redis/service.yaml
kubectl wait --for=condition=ready pod -l app=redis -n dev-infra --timeout=120s
kubectl get pods -n dev-infra -l app=redis
접속 테스트:
kubectl run redis-test --rm -it --restart=Never -n dev-infra \
--image=redis:7-alpine -- \
redis-cli -h redis-svc -a redispass1234! ping
# 기대: PONG
8단계: MinIO 배포
kubectl apply -f 05-minio/deployment.yaml
kubectl apply -f 05-minio/service.yaml
kubectl wait --for=condition=ready pod -l app=minio -n dev-infra --timeout=120s
kubectl get pods -n dev-infra -l app=minio
Console 접근 (별도 터미널):
kubectl port-forward -n dev-infra svc/minio-svc 9001:9001
# 브라우저에서 http://localhost:9001
# 로그인: minioadmin / minioadmin1234!
9단계: Init Jobs 실행
kubectl apply -f 08-init-jobs/postgres-init-job.yaml
kubectl apply -f 08-init-jobs/minio-init-job.yaml
# 완료 대기
kubectl wait --for=condition=complete job/postgres-init -n dev-infra --timeout=60s
kubectl wait --for=condition=complete job/minio-init -n dev-infra --timeout=60s
# 결과 확인
kubectl logs -n dev-infra job/postgres-init
kubectl logs -n dev-infra job/minio-init
10단계: FastAPI 배포 (커스텀 이미지 필요)
FastAPI는 커스텀 이미지를 빌드해서 kind 클러스터에 로드해야 합니다.
# 이미지 빌드 (podman)
podman build -t fastapi-app:latest -f dockerfiles/fastapi/Dockerfile src/backend/
# kind 클러스터에 이미지 로드
KIND_EXPERIMENTAL_PROVIDER=podman kind load docker-image fastapi-app:latest --name dev-infra
deployment.yaml 이미지 참조를 수정해야 합니다:
- localhost:5000/fastapi-app:latest → fastapi-app:latest
- imagePullPolicy: Always → imagePullPolicy: Never
kubectl apply -f 06-fastapi/configmap.yaml
kubectl apply -f 06-fastapi/deployment.yaml
kubectl apply -f 06-fastapi/service.yaml
kubectl wait --for=condition=ready pod -l app=fastapi -n dev-infra --timeout=180s
API 확인 (별도 터미널):
kubectl port-forward -n dev-infra svc/fastapi-svc 8000:8000
# 브라우저에서 http://localhost:8000/docs
11단계: Frontend 배포 (커스텀 이미지 필요)
# React 앱 빌드 + 이미지 생성 (src/frontend에 소스 필요)
podman build -t frontend-app:latest -f dockerfiles/frontend/Dockerfile src/frontend/
# kind에 로드
KIND_EXPERIMENTAL_PROVIDER=podman kind load docker-image frontend-app:latest --name dev-infra
deployment.yaml 이미지 참조를 수정해야 합니다:
- localhost:5000/frontend-app:latest → frontend-app:latest
- imagePullPolicy: Always → imagePullPolicy: Never
kubectl apply -f 07-frontend/configmap-nginx.yaml
kubectl apply -f 07-frontend/deployment.yaml
kubectl apply -f 07-frontend/service.yaml
전체 상태 확인
kubectl get all -n dev-infra
정리
# 클러스터 전체 삭제
KIND_EXPERIMENTAL_PROVIDER=podman kind delete cluster --name dev-infra
디스크 관리 팁
# Podman 이미지 캐시 정리
podman image prune -a
# Podman machine 디스크 사용량 확인
podman machine ssh -- df -h /
반응형
'개발 이야기 > 인프라 구축 및 운영' 카테고리의 다른 글
| gcloud 로 functions 생성 시 참고사항 (0) | 2026.03.01 |
|---|---|
| AWS Cognito 자격 증명 풀의 액세스 제어 관련 속성 상세 (0) | 2025.09.28 |
| k8s 를 위한 기본 설정 + 사이드카 (1) | 2025.08.19 |
| 보안망에서 docker를 대신할 podman (2) | 2025.08.18 |
| docker 불필요한 이미지 정리 (0) | 2025.05.05 |