Skip to content

master0419/MLops

Repository files navigation

제주은행 자금예측 MLOps

Docker 컨테이너 기반 MLOps 환경. LightGBM/PyTorch를 사용한 자금예측 모델의 학습·검증·서빙을 지원합니다.

아키텍처

┌─────────────────────────────────────────────────────────┐
│  Nginx Reverse Proxy (:80)                              │
│  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐   │
│  │JupyterHub│ │  MLflow  │ │ FastAPI  │ │  MinIO   │   │
│  │  (:8000) │ │  (:5000) │ │  (:8080) │ │(:9000/01)│   │
│  └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘   │
│       └─────────────┴────────────┴─────────────┘         │
│                         │                                │
│                  ┌──────┴──────┐                         │
│                  │ PostgreSQL  │                         │
│                  │   (:5432)   │                         │
│                  └─────────────┘                         │
└─────────────────────────────────────────────────────────┘

서비스 구성

서비스 포트 설명
JupyterHub 8000 다중 사용자 노트북 환경 (Colab 대체) + Jupyter AI (LLM 연동)
MLflow 5000 실험 관리, 모델 레지스트리
FastAPI 8080 모델 서빙 REST API
MinIO 9000/9001 오브젝트 스토리지 (데이터 캐시, 모델 아티팩트)
PostgreSQL 5432 메타데이터 저장소
Nginx 80 리버스 프록시, 통합 진입점

빠른 시작

사전 요구사항

  • Windows 11
  • Docker Desktop (WSL2 백엔드)
  • Git

1. 프로젝트 클론

git clone https://github.com/your-username/mlops.git
cd mlops

2. 환경 변수 설정

Copy-Item .env.example .env
# .env 파일을 편집하여 API 키 등 설정

3. 개발 환경 실행 (CPU 모드, 노트북 PC)

# PowerShell 스크립트 사용
.\scripts\start-dev.ps1

# 또는 직접 실행
docker compose -f docker-compose-dev.yml up -d

4. 운영 환경 실행 (GPU 모드, 5090 서버)

.\scripts\start-prod.ps1

# 또는 직접 실행
docker compose up -d

5. 접속

서비스 URL
JupyterHub http://localhost:8000
MLflow http://localhost:5000
API Docs http://localhost:8080/docs
MinIO Console http://localhost:9001

프로젝트 구조

MLops/
├── docker/
│   ├── Dockerfile.train          # 학습용 이미지 (CPU/GPU 자동 선택)
│   ├── Dockerfile.jupyter        # JupyterHub + Jupyter AI
│   └── Dockerfile.mlflow         # MLflow 서버
├── docker-compose.yml            # 운영 환경 (GPU 모드)
├── docker-compose-dev.yml        # 개발 환경 (CPU 모드)
├── Jenkinsfile                   # CI/CD 파이프라인
├── src/
│   ├── data/
│   │   ├── extract.py            # 데이터 수집 (MinIO/API/DB)
│   │   └── preprocess.py         # 전처리 & 피처 엔지니어링
│   ├── models/
│   │   ├── train.py              # 모델 학습 (LightGBM/PyTorch)
│   │   ├── evaluate.py           # 모델 평가
│   │   └── predict.py            # 예측
│   ├── utils/
│   │   ├── config.py             # 설정 관리
│   │   └── db_connector.py       # 데이터 소스 연결 (MinIO/API/DB)
│   └── api/
│       └── main.py               # FastAPI 서빙
├── configs/
│   ├── model_config.yaml         # 모델 하이퍼파라미터
│   └── db_config.yaml            # DB 연결 설정
├── notebooks/
│   └── 01_eda_fund_prediction.ipynb  # 탐색적 분석 노트북
├── tests/                        # 테스트 코드
├── nginx/                        # Nginx 설정
├── jupyterhub/                   # JupyterHub 설정
├── scripts/                      # 실행 스크립트
├── requirements/
│   ├── requirements-train.txt    # 학습 환경 패키지
│   └── requirements-jupyter.txt  # Jupyter 환경 패키지
├── .env.example                  # 환경변수 템플릿
└── .gitignore

데이터 소스 전환

환경변수 DATA_SOURCE로 데이터 소스 전환:

# MinIO (기본, 개발용)
DATA_SOURCE=minio

# 제주은행 API
DATA_SOURCE=api

# 제주은행 DB 직접 연결
DATA_SOURCE=direct

모델 학습

JupyterHub에서 (인터랙티브)

  1. http://localhost:8000 접속
  2. notebooks/01_eda_fund_prediction.ipynb 열기
  3. 셀 실행

CLI로 학습 실행

# 샘플 데이터로 LightGBM 학습
docker compose -f docker-compose-dev.yml --profile training run --rm trainer \
  python -m src.models.train --model-name lightgbm --sample-data

# LSTM 학습
docker compose -f docker-compose-dev.yml --profile training run --rm trainer \
  python -m src.models.train --model-name lstm --sample-data

Jupyter AI (LLM 연동)

.env에 API 키 설정:

OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...

노트북에서 사용:

%%ai chatgpt
 모델의 성능을 개선할 방법을 알려줘

%%ai claude  
하이퍼파라미터 튜닝 코드를 작성해줘

Jenkins CI/CD

Jenkins 서버(제주은행 서버)에서 이 저장소의 Jenkinsfile을 파이프라인으로 등록하면:

  1. Code Checkout → Git에서 코드 가져오기
  2. Code Quality → Lint, Type Check
  3. Build Images → Docker 이미지 빌드
  4. Unit Tests → 자동 테스트
  5. Model Training → 모델 학습 (선택)
  6. Model Validation → 성능 검증
  7. Push Images → Docker Registry에 푸시
  8. Deploy → 운영 서버에 배포

GPU 전환 (로컬 → 5090 서버)

  1. 5090 서버에 NVIDIA Driver 570+ 설치
  2. NVIDIA Container Toolkit 설치
  3. 동일한 코드를 서버에 클론
  4. docker compose up -d 실행 (GPU 자동 인식)

dev 환경과 prod 환경의 차이는 GPU 할당 유무뿐이므로, 코드 수정 없이 전환 가능합니다.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors