-
Notifications
You must be signed in to change notification settings - Fork 1
API Documents
윤지원 edited this page Nov 16, 2025
·
4 revisions
K8s 기반 자동 개발 환경 프로비저닝 시스템의 API 명세서입니다.
기본 URL: http://localhost:8000/api/v1
Swagger UI: http://localhost:8000/docs
ReDoc: http://localhost:8000/redoc
모든 API 엔드포인트는 Bearer 토큰 인증을 사용합니다.
Authorization: Bearer <your-jwt-token>POST /auth/login
{
"email": "user@example.com",
"password": "password123"
}POST /environments/
{
"name": "My React Project",
"template_id": 1,
"git_repository": "https://github.com/user/project.git",
"git_branch": "main",
"expires_at": "2024-12-31T23:59:59Z"
}GET /environments/
GET /environments/?status=running&user_id=1POST /environments/{id}/actions
{
"action": "start" // start, stop, restart, delete
}GET /environments/{id}/logs?tail_lines=100GET /environments/{id}/access-info응답 예시:
{
"environment_id": 1,
"access_url": "http://env-my-react-project.kubdev.local",
"status": "running",
"ports": [8080]
}POST /templates/
{
"name": "React + TypeScript Starter",
"description": "React 18 + TypeScript + Vite 개발환경",
"base_image": "codercom/code-server:latest",
"stack_config": {
"language": "javascript",
"framework": "react",
"version": "18"
},
"dependencies": ["nodejs", "npm", "git"],
"resource_limits": {
"cpu": "1000m",
"memory": "2Gi",
"storage": "10Gi"
},
"exposed_ports": [3000, 8080],
"environment_variables": {
"NODE_ENV": "development"
}
}GET /templates/?status=active&organization_id=1POST /templates/{id}/validatePOST /templates/{id}/test-deploy?timeout_seconds=300GET /admin/overview응답 예시:
{
"cluster_overview": {
"cluster_info": {
"total_nodes": 3,
"ready_nodes": 3,
"total_pods": 25,
"running_pods": 23
},
"kubdev_info": {
"total_environments": 8,
"active_environments": 6,
"pending_environments": 2,
"failed_environments": 0
}
}
}GET /admin/environments** 핵심 기능**: K8s에서 실시간 상태를 조회하여 다음 정보 제공:
- Pod 상태 (Running/Pending/Failed)
- ResourceQuota 사용률 (CPU 65%, Memory 78% 등)
- 네임스페이스별 리소스 현황
- 컨테이너 Ready 상태
GET /admin/namespace/{namespace}GET /monitoring/user/{user_id}/environmentsGET /monitoring/environments/{id}/metrics?hours=24GET /admin/alerts알림 예시:
{
"alerts": [
{
"type": "warning",
"category": "high_resource_usage",
"message": "High CPU usage in namespace 'lisa-project-a'",
"cpu_usage": "85%",
"memory_usage": "72%"
}
]
}GET /admin/overviewGET /admin/users-activity?limit=50GET /admin/templates-usagePOST /admin/cleanup/expired?dry_run=true- super_admin: 모든 권한
- org_admin: 조직 내 모든 관리
- team_leader: 팀 내 환경 관리
- developer: 본인 환경만 관리
POST /auth/api-keys
{
"description": "CI/CD 파이프라인용 API 키"
}- Admin: 템플릿 생성
POST /templates/
# "React 개발환경" 템플릿 생성- 신입 개발자: 환경 생성 요청
POST /environments/
{
"name": "Lisa의 첫 프로젝트",
"template_id": 1,
"git_repository": "https://github.com/company/onboarding-project"
}-
백엔드 자동 처리:
- ✅
lisa-project-aNamespace 생성 - ✅ ResourceQuota 자동 적용 (CPU 1개, 메모리 2GB 제한)
- ✅ Init Container가 Git 저장소 클론
- ✅ VS Code Server 컨테이너 시작
- ✅ Ingress로 외부 접속 URL 생성
- ✅
-
결과:
- Lisa는
http://env-lisa-project-a.kubdev.local로 즉시 접속 - 웹 브라우저에서 VS Code 사용
- 프로젝트 코드 미리 로드됨
- Lisa는
-
Admin 모니터링:
GET /admin/environments
# Lisa의 환경 상태 실시간 확인
# CPU 사용률: 45%, 메모리: 68% 등# 1. 환경 생성 전
kubectl get namespaces
# lisa-project-a 없음
# 2. 환경 생성 후
kubectl get namespaces
# lisa-project-a Active
kubectl get all -n lisa-project-a
# Deployment, Service, Pod 모두 Running
kubectl get resourcequota -n lisa-project-a
# CPU 1개, 메모리 2GB 제한 적용됨- Lens 연결 후 실시간으로 Namespace 생성 과정 시각적 확인
- Pod 상태 변화: Pending → ContainerCreating → Running
- ResourceQuota 제한 실시간 모니터링
- 자동 생성: 환경 생성시 ResourceQuota 자동 적용
- 과부하 방지: 무한루프 코드 실행해도 CPU 1개로 제한
- 멀티테넌트: 사용자별 독립된 리소스 할당량
-
K8s API 연동:
kubectl get동급의 실시간 데이터 - 사용률 추적: CPU 65%, 메모리 78% 등 정확한 수치
- 알림 시스템: 임계값 초과시 자동 알림
- 통합 모니터링: 모든 환경 상태 한눈에 확인
- 리소스 효율화: 비효율적 사용 패턴 식별
- 자동 정리: 만료된 환경 자동 삭제
POST /api/v1/templates/generate-dockerfile
Content-Type: application/json
{
"stack_config": {
"language": "node",
"version": "18",
"framework": "react",
"dependencies": ["axios", "react-router-dom", "styled-components"],
"exposed_ports": [3000],
"environment_variables": {
"NODE_ENV": "development",
"REACT_APP_API_URL": "http://localhost:8000"
}
},
"environment_id": "env-react-demo",
"validate_only": false
}응답 (성공):
{
"status": "success",
"dockerfile": "FROM node:18-alpine\n\n# Generated by KubeDev Auto System...",
"image_tag": "kubdev/env-react-demo:latest",
"environment_id": "env-react-demo",
"stack_config": {...},
"build_time": "2024-11-16T10:30:00Z"
}지원 스택:
- Node.js: React, Express, NestJS, Next.js
- Python: Django, FastAPI, Flask, ML/Data Science
- Java: Spring Boot, Maven, Gradle
- Go: Gin, Fiber, Echo
GET /api/v1/templates/supported-stacks응답:
{
"supported_stacks": {
"languages": ["node", "python", "java", "go"],
"frameworks": {
"node": ["react", "express", "nest", "next"],
"python": ["django", "fastapi", "flask", "ml"],
"java": ["spring", "maven", "gradle"],
"go": ["gin", "fiber", "echo"]
},
"base_images": {
"node": {
"16": "node:16-alpine",
"18": "node:18-alpine",
"20": "node:20-alpine"
}
}
},
"examples": {
"node_react": {
"language": "node",
"version": "18",
"framework": "react",
"dependencies": ["axios", "react-router-dom"],
"exposed_ports": [3000],
"environment_variables": {
"NODE_ENV": "development"
}
},
"python_fastapi": {
"language": "python",
"version": "3.11",
"framework": "fastapi",
"dependencies": ["sqlalchemy", "pandas"],
"exposed_ports": [8000],
"environment_variables": {
"PYTHONPATH": "/workspace"
}
}
}
}POST /api/v1/templates/{template_id}/generate-custom-image?build_now=true응답:
{
"status": "success",
"template_id": 1,
"template_name": "React Development Environment",
"dockerfile": "FROM node:18-alpine...",
"image_tag": "kubdev/template-1-abc123:latest",
"environment_id": "template-1-abc123",
"build_time": "2024-11-16T10:35:00Z",
"message": "Custom image built successfully"
}POST /api/v1/admin/users/batch
Content-Type: application/json
{
"prefix": "camp2024",
"count": 100,
"template_id": 1,
"organization_id": 1,
"resource_quota": {
"cpu": "1",
"memory": "2Gi",
"storage": "10Gi"
}
}응답 (실행 완료):
{
"status": "completed",
"created_count": 98,
"failed_count": 2,
"total_requested": 100,
"users": [
{
"username": "camp2024-01",
"email": "camp2024-01@kubdev.local",
"password": "Kx9#mP2$vQ8!",
"user_id": 101,
"environment_id": 201,
"namespace": "kubdev-camp2024-01",
"access_url": "https://camp2024-01.ide.kubdev.io",
"status": "creating",
"expires_at": "2024-11-16T18:30:00Z",
"created_at": "2024-11-16T10:30:00Z"
},
{
"username": "camp2024-02",
"email": "camp2024-02@kubdev.local",
"password": "Qp7&nL5%rT3@",
"user_id": 102,
"environment_id": 202,
"namespace": "kubdev-camp2024-02",
"access_url": "https://camp2024-02.ide.kubdev.io",
"status": "creating",
"expires_at": "2024-11-16T18:30:00Z",
"created_at": "2024-11-16T10:30:15Z"
}
],
"failures": [
{
"username": "camp2024-99",
"error": "K8s resource creation failed: namespace already exists",
"timestamp": "2024-11-16T10:32:00Z"
},
{
"username": "camp2024-100",
"error": "Database connection timeout",
"timestamp": "2024-11-16T10:32:05Z"
}
],
"template_name": "React Development Environment",
"resource_quota": {
"cpu": "1",
"memory": "2Gi",
"storage": "10Gi"
},
"execution_time": "142.35s",
"timestamp": "2024-11-16T10:32:30Z"
}자동 생성되는 K8s 리소스:
- ✅ Namespace:
kubdev-{username} - ✅ ResourceQuota: CPU/메모리/스토리지 제한
- ✅ Deployment: VS Code Server + 프로젝트 환경
- ✅ Service: 내부 통신용
- ✅ Ingress: 외부 접속 URL (
https://{username}.ide.kubdev.io) - ✅ PVC: 개인 워크스페이스 (10GB)
POST /api/v1/admin/users/single
Content-Type: application/json
{
"username": "newbie-alice",
"template_id": 2,
"password": "custom123!",
"organization_id": 1,
"resource_quota": {
"cpu": "2",
"memory": "4Gi",
"storage": "20Gi"
}
}응답:
{
"status": "success",
"user": {
"username": "newbie-alice",
"email": "newbie-alice@kubdev.local",
"password": "custom123!",
"user_id": 203
},
"environment": {
"environment_id": 301,
"namespace": "kubdev-newbie-alice",
"status": "creating",
"expires_at": "2024-11-16T18:45:00Z"
},
"access_info": {
"access_url": "https://newbie-alice.ide.kubdev.io",
"username": "newbie-alice",
"password": "custom123!"
},
"template_name": "Python FastAPI Environment",
"timestamp": "2024-11-16T10:45:00Z"
}DELETE /api/v1/admin/users/batch?prefix=camp2024&dry_run=false응답:
{
"status": "completed",
"prefix": "camp2024",
"users_found": 98,
"deleted_count": 96,
"failed_count": 2,
"details": [
{
"user_id": 101,
"username": "camp2024-01",
"email": "camp2024-01@kubdev.local",
"status": "deleted"
},
{
"user_id": 150,
"username": "camp2024-50",
"email": "camp2024-50@kubdev.local",
"status": "failed",
"reason": "Active environment deletion failed"
}
],
"dry_run": false,
"timestamp": "2024-11-16T11:00:00Z"
}# 1단계: React 환경 템플릿 생성 (Dockerfile 자동생성)
curl -X POST "http://localhost:8000/api/v1/templates/generate-dockerfile" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"stack_config": {
"language": "node",
"version": "18",
"framework": "react",
"dependencies": ["axios", "react-router-dom", "styled-components"],
"exposed_ports": [3000],
"environment_variables": {
"NODE_ENV": "development"
}
},
"environment_id": "bootcamp-react-2024",
"validate_only": false
}'
# 2단계: 100명 계정 일괄 생성
curl -X POST "http://localhost:8000/api/v1/admin/users/batch" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"prefix": "bootcamp2024",
"count": 100,
"template_id": 1,
"resource_quota": {
"cpu": "1",
"memory": "2Gi",
"storage": "10Gi"
}
}'
# 결과: 5-10분 내 100개 IDE 환경 완성
# - bootcamp2024-01.ide.kubdev.io
# - bootcamp2024-02.ide.kubdev.io
# - ...
# - bootcamp2024-100.ide.kubdev.io# Python FastAPI 환경 즉시 생성
curl -X POST "http://localhost:8000/api/v1/admin/users/single" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"username": "junior-kim",
"template_id": 3,
"password": "welcome123!",
"resource_quota": {
"cpu": "2",
"memory": "4Gi",
"storage": "20Gi"
}
}'
# 결과: 3-5초 내 https://junior-kim.ide.kubdev.io 접속 가능# 1. 미리보기 (dry_run=true)
curl -X DELETE "http://localhost:8000/api/v1/admin/users/batch?prefix=bootcamp2024&dry_run=true" \
-H "Authorization: Bearer $TOKEN"
# 2. 실제 삭제 (dry_run=false)
curl -X DELETE "http://localhost:8000/api/v1/admin/users/batch?prefix=bootcamp2024&dry_run=false" \
-H "Authorization: Bearer $TOKEN"
# 결과: 모든 bootcamp2024-* 계정 및 K8s 리소스 정리| 지표 | 성능 |
|---|---|
| 단일 환경 생성 시간 | 3-5초 |
| 대량 생성 (100명) | 5-10분 |
| 동시 생성 제한 | 10개 (세마포어) |
| 최대 일괄 생성 | 200명 |
| 자동 만료 시간 | 8시간 (설정 가능) |
| 지원 언어 | 4개 (Node.js, Python, Java, Go) |
| 지원 프레임워크 | 15+ 개 |