This commit is contained in:
hiondal
2025-06-15 14:15:05 +00:00
parent d170dafd01
commit c7da54179b
7 changed files with 281 additions and 146 deletions
+48 -19
View File
@@ -1,63 +1,92 @@
# deployment/manifests/configmap.yaml - 홈 디렉토리 전환 적용
apiVersion: v1
kind: ConfigMap
metadata:
name: vector-api-config
labels:
app: vector-api
data:
# 🔧 기존 애플리케이션 설정 (유지)
# 🏠 홈 디렉토리 기반 경로 설정
APP_ROOT: "/home/appuser"
# 🔧 애플리케이션 설정
APP_TITLE: "음식점 Vector DB 구축 서비스"
APP_VERSION: "1.0.0"
APP_DESCRIPTION: "소상공인을 위한 AI 기반 경쟁업체 분석 및 액션 추천 시스템"
# 🔧 기존 서버 설정 (유지)
# 🔧 서버 설정
HOST: "0.0.0.0"
PORT: "8000"
LOG_LEVEL: "debug" # 디버깅을 위해 debug로 변경
LOG_LEVEL: "info"
# 🔧 기존 Restaurant API 설정 (K8s 환경, 유지)
# 🏠 홈 디렉토리 기반 파일 경로들
VECTOR_DB_PATH: "/home/appuser/vectordb"
DATA_DIR: "/home/appuser/data"
LOG_DIR: "/home/appuser/logs"
# 🔧 Restaurant API 설정 (K8s 환경)
RESTAURANT_API_HOST: "restaurant-api-service"
RESTAURANT_API_PORT: "80"
# 🔧 기존 Review API 설정 (K8s 환경, 유지)
# 🔧 Review API 설정 (K8s 환경)
REVIEW_API_HOST: "kakao-review-api-service"
REVIEW_API_PORT: "80"
# 🔧 기존 Claude API 설정 (유지)
# 🔧 Claude API 설정
CLAUDE_MODEL: "claude-sonnet-4-20250514"
# 🔧 기존 Vector DB 설정 (유지)
VECTOR_DB_PATH: "/app/vectordb"
# 🔧 Vector DB 설정
VECTOR_DB_COLLECTION: "restaurant_reviews"
EMBEDDING_MODEL: "sentence-transformers/all-MiniLM-L6-v2"
# 🔧 기존 데이터 수집 설정 (유지)
# 🔧 데이터 수집 설정
MAX_RESTAURANTS_PER_CATEGORY: "50"
MAX_REVIEWS_PER_RESTAURANT: "100"
REQUEST_DELAY: "0.1"
REQUEST_TIMEOUT: "600"
# 🆕 ChromaDB 최신 버전 호환 설정 추가
CHROMA_DB_IMPL: "duckdb+parquet" # SQLite 대신 DuckDB 사용
# 🔧 ChromaDB 설정
CHROMA_DB_IMPL: "duckdb+parquet"
ALLOW_RESET: "True"
ANONYMIZED_TELEMETRY: "False"
# 🆕 Python 최적화 설정
# 🔧 Python 최적화 설정
PYTHONUNBUFFERED: "1"
PYTHONDONTWRITEBYTECODE: "1"
# 🆕 캐시 디렉토리 설정
HF_HUB_CACHE: "/app/.cache/huggingface"
TRANSFORMERS_CACHE: "/app/.cache/transformers"
# 🏠 홈 디렉토리 기반 캐시 디렉토리 설정
HF_HUB_CACHE: "/home/appuser/.cache/huggingface"
TRANSFORMERS_CACHE: "/home/appuser/.cache/transformers"
SENTENCE_TRANSFORMERS_HOME: "/home/appuser/.cache/sentence_transformers"
# 🆕 FastAPI 설정
# 🔧 Poetry 캐시 설정
POETRY_CACHE_DIR: "/home/appuser/.cache/pypoetry/cache"
POETRY_VENV_PATH: "/home/appuser/.cache/pypoetry/venvs"
# 🔧 FastAPI 설정
FASTAPI_ENV: "production"
# 🆕 Uvicorn 설정
# 🔧 Uvicorn 설정
UVICORN_HOST: "0.0.0.0"
UVICORN_PORT: "8000"
UVICORN_LOG_LEVEL: "debug"
UVICORN_LOG_LEVEL: "info"
UVICORN_ACCESS_LOG: "true"
# 🆕 타임아웃 설정
# 🔧 타임아웃 설정
STARTUP_TIMEOUT: "300" # 5분
SHUTDOWN_TIMEOUT: "30" # 30초
# 🔧 메모리 및 성능 설정
TORCH_NUM_THREADS: "2"
OMP_NUM_THREADS: "2"
TOKENIZERS_PARALLELISM: "false"
# 🔧 보안 설정
DISABLE_TELEMETRY: "true"
NO_PROXY: "localhost,127.0.0.1"
# 🔧 로깅 설정
LOG_FORMAT: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
LOG_MAX_BYTES: "10485760" # 10MB
LOG_BACKUP_COUNT: "5"
+96 -60
View File
@@ -1,12 +1,21 @@
# deployment/manifests/deployment.yaml.fixed
# deployment/manifests/deployment.yaml - 간소화된 버전 (initContainer 제거)
apiVersion: apps/v1
kind: Deployment
metadata:
name: vector-api
labels:
app: vector-api
version: v1.0.0
annotations:
deployment.kubernetes.io/revision: "1"
description: "Vector DB API with Simplified Home Directory Structure"
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
selector:
matchLabels:
app: vector-api
@@ -14,55 +23,53 @@ spec:
metadata:
labels:
app: vector-api
version: v1.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
prometheus.io/path: "/metrics"
spec:
# 🔧 볼륨 권한 설정을 위한 initContainer
initContainers:
- name: volume-permissions
image: busybox:1.35
command:
- /bin/sh
- -c
- |
echo "=== 볼륨 권한 설정 시작 ==="
mkdir -p /app/vectordb
chown -R 1000:1000 /app/vectordb
chmod -R 755 /app/vectordb
echo "=== 볼륨 권한 설정 완료 ==="
volumeMounts:
- name: vector-db-storage
mountPath: /app/vectordb
securityContext:
runAsUser: 0
# 🚫 initContainer 제거 - 홈 디렉토리 사용으로 불필요
containers:
- name: vector-api
image: acrdigitalgarage03.azurecr.io/vector-api:latest
imagePullPolicy: Always
# 🔧 컨테이너 포트
ports:
- containerPort: 8000
- name: http
containerPort: 8000
protocol: TCP
# 🔧 보안 컨텍스트
# 🔧 보안 컨텍스트 (appuser 사용)
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
readOnlyRootFilesystem: false
capabilities:
drop:
- ALL
# 🔧 리소스 설정
resources:
requests:
memory: "4Gi"
cpu: "1000m"
ephemeral-storage: "2Gi"
limits:
memory: "8Gi"
cpu: "2000m"
ephemeral-storage: "5Gi"
# 🏥 헬스체크 설정
livenessProbe:
httpGet:
path: /health
port: 8000
port: http
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 30
timeoutSeconds: 15
@@ -71,66 +78,85 @@ spec:
readinessProbe:
httpGet:
path: /health
port: 8000
port: http
scheme: HTTP
initialDelaySeconds: 60
periodSeconds: 10
timeoutSeconds: 10
failureThreshold: 3
# 📂 볼륨 마운트
# 🚀 시작 프로브 (초기 시작 시간 고려)
startupProbe:
httpGet:
path: /health
port: http
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 10
failureThreshold: 30 # 최대 5분 대기
successThreshold: 1
# 📂 볼륨 마운트 (홈 디렉토리 기반)
volumeMounts:
- name: vector-db-storage
mountPath: /app/vectordb
mountPath: /home/appuser/vectordb # ✅ PVC 마운트
- name: tmp-volume
mountPath: /tmp
- name: cache-volume
mountPath: /home/appuser/.cache
subPath: "vector-api"
# ConfigMap 환경 변수
# 🌍 환경변수 설정 - ConfigMap에서 모든 값 가져오기
envFrom:
- configMapRef:
name: vector-api-config
# 🌍 환경변수 설정 (인증 필드 제거)
# 🔐 Secret에서 민감한 정보 가져오기
env:
- name: PYTHONUNBUFFERED
value: "1"
- name: PYTHONDONTWRITEBYTECODE
value: "1"
# 🔧 ChromaDB 기본 설정 (인증 필드 제거)
- name: ANONYMIZED_TELEMETRY
value: "False"
- name: CHROMA_DB_IMPL
value: "duckdb+parquet"
- name: ALLOW_RESET
value: "True"
# 🔧 로그 레벨
- name: LOG_LEVEL
value: "info"
# 🔧 Claude API (ConfigMap에서 가져오기)
- name: CLAUDE_API_KEY
valueFrom:
secretKeyRef:
name: vector-api-secret
key: CLAUDE_API_KEY
- name: CLAUDE_MODEL
valueFrom:
configMapKeyRef:
name: vector-api-config
key: CLAUDE_MODEL
# 🔧 기타 설정 (ConfigMap에서 가져오기)
- name: APP_TITLE
valueFrom:
configMapKeyRef:
name: vector-api-config
key: APP_TITLE
- name: APP_VERSION
valueFrom:
configMapKeyRef:
name: vector-api-config
key: APP_VERSION
# 🔧 런타임 환경변수
- name: PYTHONPATH
value: "/home/appuser"
- name: HOME
value: "/home/appuser"
- name: USER
value: "appuser"
# 🔧 성능 최적화 환경변수
- name: MALLOC_ARENA_MAX
value: "2"
- name: MALLOC_MMAP_THRESHOLD_
value: "131072"
# 🔧 컨테이너 생명주기 관리
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- |
echo "Gracefully shutting down Vector API..."
curl -X POST http://localhost:8000/shutdown || true
sleep 10
# 📦 볼륨 설정
volumes:
- name: vector-db-storage
persistentVolumeClaim:
claimName: vector-db-pvc
- name: tmp-volume
emptyDir:
sizeLimit: 1Gi
- name: cache-volume
emptyDir:
sizeLimit: 2Gi
# 🔐 이미지 Pull Secret
imagePullSecrets:
@@ -146,6 +172,7 @@ spec:
value: "aipool"
effect: "NoSchedule"
# 🔧 Pod 배치 정책
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
@@ -159,6 +186,15 @@ spec:
- vector-api
topologyKey: kubernetes.io/hostname
# 🔧 Pod 설정
restartPolicy: Always
dnsPolicy: ClusterFirst
terminationGracePeriodSeconds: 60
# 🔧 보안 컨텍스트 (Pod 레벨)
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000