본문으로 건너뛰기

FastAPI Backend Deployment

FastAPI 기반 Python API 서버와 Kubernetes 배포 설정 (공유 저장소 포함)

목차


주요 구성 요소

리소스이름네임스페이스설명
PersistentVolumeClaimrepos-pvcgitionGit 저장소 공유를 위한 NFS 볼륨 (5Gi, RWX)
Deploymentapigition백엔드 애플리케이션 (Replicas: 3)
Serviceapi-svcgition백엔드 서비스 (Port: 3001)

컨테이너 설정

항목
Replicas3 (3개의 Pod가 저장소 공유)
이미지172.100.100.8:5050/root/gition/backend:latest
포트3001
imagePullSecretsgitlab-registry

공유 저장소 (Shared Storage)

Replicas가 3개이므로, 모든 Pod가 동일한 Git 저장소 데이터를 볼 수 있도록 NFS PVC를 마운트함

종류이름마운트 경로
VolumeMountrepos-volume/repos
PVCrepos-pvcnfs-client StorageClass 사용

환경 변수 설정

Database

변수명설명
MYSQL_READ_HOSTmysql-master현재 Master에서 Read/Write 모두 처리
MYSQL_WRITE_HOSTmysql-master쓰기 전용 DB (Master)
MYSQL_PORT3306MySQL 포트
MYSQL_USERpistaDB 사용자
MYSQL_DATABASEgitionDB 이름
MYSQL_PASSWORDSecret 참조mysql-secret.user-password

Application URLs

변수명설명
BASE_URLhttp://gition.local백엔드 기본 URL
FRONTEND_URLhttp://gition.local프론트엔드 URL (OAuth 리다이렉트)
ALLOWED_ORIGINShttp://gition.local,http://127.0.0.1,http://localhostCORS 허용 Origins
REPOS_PATH/reposGit 저장소 경로 (공유 볼륨)

GitHub OAuth

변수명설명
GITHUB_CLIENT_IDSecret 참조github-secret.client-id
GITHUB_CLIENT_SECRETSecret 참조github-secret.client-secret

리소스 제한

항목RequestsLimits
CPU100m500m
Memory128Mi512Mi

Health Check

ProbePathInitial DelayPeriod
Liveness/health30s60s
Readiness/health15s60s

배포 관련

배포 명령어

kubectl apply -f fastapi-deployment.yaml
kubectl get pods -n gition -l app=api

새 이미지가 배포 하는 경우

# k8s-m에서 실행
kubectl rollout restart deployment/api -n gition
# 상태 확인
kubectl rollout status deployment/api -n gition
#결과 : deployment "api" successfully rolled out

관련 문서

그래프 뷰

그래프 데이터 로딩 중…
현재: FastAPI Backend Deployment
노드 클릭 → 이동 · 드래그 → 위치 조정