This commit is contained in:
hiondal
2025-06-15 21:23:51 +00:00
parent 42dd563205
commit c737cd8210
5 changed files with 164 additions and 507 deletions
+41 -60
View File
@@ -1,98 +1,79 @@
# deployment/manifests/configmap.yaml - 홈 디렉토리 전환 적용
# deployment/manifests/configmap.yaml - ChromaDB 1.0.12 호환 설정
apiVersion: v1
kind: ConfigMap
metadata:
name: vector-api-config
labels:
app: vector-api
version: v1.0.10
data:
# 🏠 홈 디렉토리 기반 경로 설정
APP_ROOT: "/home/appuser"
# 🔧 애플리케이션 설정
# 🔧 애플리케이션 기본 설정
APP_TITLE: "음식점 Vector DB 구축 서비스"
APP_VERSION: "1.0.0"
APP_VERSION: "1.0.10"
APP_DESCRIPTION: "소상공인을 위한 AI 기반 경쟁업체 분석 및 액션 추천 시스템"
ENVIRONMENT: "production"
# 🔧 서버 설정
HOST: "0.0.0.0"
PORT: "8000"
LOG_LEVEL: "info"
# 🏠 홈 디렉토리 기반 파일 경로들
# 🗄️ 데이터 디렉토리
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_HOST: "kakao-review-api-service"
REVIEW_API_PORT: "80"
# 🔧 Claude API 설정
# 🤖 AI/ML 설정
CLAUDE_MODEL: "claude-sonnet-4-20250514"
# 🔧 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"
ALLOW_RESET: "True"
ANONYMIZED_TELEMETRY: "False"
# 🔧 Python 최적화 설정
PYTHONUNBUFFERED: "1"
PYTHONDONTWRITEBYTECODE: "1"
# 🏠 홈 디렉토리 기반 캐시 디렉토리 설정
HF_HUB_CACHE: "/home/appuser/.cache/huggingface"
TRANSFORMERS_CACHE: "/home/appuser/.cache/transformers"
SENTENCE_TRANSFORMERS_HOME: "/home/appuser/.cache/sentence_transformers"
# 🔧 Poetry 캐시 설정
POETRY_CACHE_DIR: "/home/appuser/.cache/pypoetry/cache"
POETRY_VENV_PATH: "/home/appuser/.cache/pypoetry/venvs"
POETRY_CONFIG_DIR: "/home/appuser/.config/pypoetry"
POETRY_DATA_DIR: "/home/appuser/.local/share/pypoetry"
POETRY_NO_INTERACTION: "1"
POETRY_VENV_IN_PROJECT: "false"
POETRY_VIRTUALENVS_CREATE: "true"
# 🗄️ ChromaDB 설정 (1.0.12 호환)
# ❌ 제거된 deprecated 설정들:
# CHROMA_DB_IMPL: "duckdb+parquet" # deprecated
# ALLOW_RESET: "True" # deprecated
# ANONYMIZED_TELEMETRY: "False" # deprecated
# 🔧 FastAPI 설정
FASTAPI_ENV: "production"
# 🔧 Uvicorn 설정
UVICORN_HOST: "0.0.0.0"
UVICORN_PORT: "8000"
UVICORN_LOG_LEVEL: "info"
UVICORN_ACCESS_LOG: "true"
# 🔧 타임아웃 설정
STARTUP_TIMEOUT: "300" # 5분
SHUTDOWN_TIMEOUT: "30" # 30초
# 🔧 메모리 및 성능 설정
# ✅ 새로운 ChromaDB 1.0.12 설정
CHROMA_PERSISTENT: "true"
CHROMA_ALLOW_RESET: "true"
CHROMA_ANONYMIZED_TELEMETRY: "false"
# 🚀 성능 최적화
TORCH_NUM_THREADS: "2"
OMP_NUM_THREADS: "2"
TOKENIZERS_PARALLELISM: "false"
# 🔧 보안 설정
MALLOC_ARENA_MAX: "2"
# 🔧 Python 환경
PYTHONUNBUFFERED: "1"
PYTHONDONTWRITEBYTECODE: "1"
PYTHONPATH: "/home/appuser"
# 🗂️ 캐시 디렉토리
HF_HUB_CACHE: "/home/appuser/.cache/huggingface"
TRANSFORMERS_CACHE: "/home/appuser/.cache/transformers"
SENTENCE_TRANSFORMERS_HOME: "/home/appuser/.cache/sentence_transformers"
# 🔧 Poetry 설정 (Base Image 호환)
POETRY_NO_INTERACTION: "1"
# 🔧 보안 및 네트워크
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"
+80 -175
View File
@@ -1,20 +1,20 @@
# deployment/manifests/deployment.yaml - initContainer로 권한 문제 해결
# deployment/manifests/deployment.yaml - Base Image 호환 버전
apiVersion: apps/v1
kind: Deployment
metadata:
name: vector-api
labels:
app: vector-api
version: v1.0.0
version: v1.0.9
annotations:
deployment.kubernetes.io/revision: "1"
description: "Vector DB API with initContainer Permission Fix"
deployment.kubernetes.io/revision: "9"
description: "Vector DB API with Base Image Compatibility"
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
@@ -23,71 +23,51 @@ spec:
metadata:
labels:
app: vector-api
version: v1.0.0
version: v1.0.9
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
prometheus.io/path: "/metrics"
spec:
# 🚀 initContainer로 Poetry 설정 파일 생성 (볼륨에)
initContainers:
- name: setup-poetry-config
image: busybox:1.35
command:
- /bin/sh
- -c
- |
echo "🔧 Poetry 설정 생성 중... (볼륨 기반)"
# 볼륨 마운트된 경로에 Poetry 설정 생성
mkdir -p /cache/poetry-config
mkdir -p /cache/poetry-data
# Poetry 설정 파일을 볼륨에 생성
cat > /cache/poetry-config/config.toml << 'EOF'
[virtualenvs]
create = true
in-project = false
path = "/home/appuser/.cache/pypoetry/venvs"
[cache-dir]
path = "/home/appuser/.cache/pypoetry/cache"
[installer]
no-cache = false
EOF
echo "✅ Poetry 설정 생성 완료!"
echo "📝 설정 파일 내용:"
cat /cache/poetry-config/config.toml
echo "📁 캐시 디렉토리:"
ls -la /cache/
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
readOnlyRootFilesystem: false
capabilities:
drop:
- ALL
volumeMounts:
- name: cache-volume
mountPath: /cache
# 🔧 initContainer 제거 - Base Image 설정 그대로 사용
containers:
- name: vector-api
image: acrdigitalgarage03.azurecr.io/vector-api:latest
imagePullPolicy: Always
# 🔧 컨테이너 포트
ports:
- name: http
containerPort: 8000
protocol: TCP
# 🔧 보안 컨텍스트 (appuser 사용)
# 🔧 환경변수 (ConfigMap만 사용, Poetry 설정 제외)
envFrom:
- configMapRef:
name: vector-api-config
env:
- name: CLAUDE_API_KEY
valueFrom:
secretKeyRef:
name: vector-api-secret
key: CLAUDE_API_KEY
- name: HOME
value: "/home/appuser"
- name: USER
value: "appuser"
# 🔧 Poetry 관련 환경변수 모두 제거 (Base Image 설정 유지)
# ❌ 제거: POETRY_CONFIG_DIR, POETRY_DATA_DIR, POETRY_CACHE_DIR
# ❌ 제거: POETRY_VENV_PATH, POETRY_VIRTUALENVS_IN_PROJECT
# 🗂️ 볼륨 마운트 (단순화)
volumeMounts:
- name: vector-db-storage
mountPath: /home/appuser/vectordb
- name: tmp-volume
mountPath: /tmp
# 🔧 보안 컨텍스트
securityContext:
runAsNonRoot: true
runAsUser: 1000
@@ -101,126 +81,66 @@ spec:
# 🔧 리소스 설정
resources:
requests:
memory: "2Gi"
cpu: "500m"
limits:
memory: "4Gi"
cpu: "1000m"
ephemeral-storage: "2Gi"
limits:
memory: "8Gi"
cpu: "2000m"
ephemeral-storage: "5Gi"
# 🏥 헬스체크 설정
# 🏥 헬스체크 (Base Image 가상환경 확인)
livenessProbe:
httpGet:
path: /health
port: http
scheme: HTTP
initialDelaySeconds: 120
exec:
command:
- /bin/sh
- -c
- |
# Base Image 가상환경 확인
poetry run python -c "import fastapi; print('✅ 정상')" 2>/dev/null || exit 1
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 15
timeoutSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /health
port: http
scheme: HTTP
initialDelaySeconds: 60
periodSeconds: 10
timeoutSeconds: 10
failureThreshold: 3
# 🚀 시작 프로브 (초기 시작 시간 고려)
startupProbe:
httpGet:
path: /health
port: http
scheme: HTTP
exec:
command:
- /bin/sh
- -c
- |
# Base Image 패키지 확인
poetry run python -c "import fastapi, uvicorn, pydantic; print('✅ 준비됨')" 2>/dev/null || exit 1
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
startupProbe:
exec:
command:
- /bin/sh
- -c
- |
# Poetry 환경 확인
poetry env info && poetry show | head -5
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 10
failureThreshold: 30 # 최대 5분 대기
successThreshold: 1
failureThreshold: 12 # 60초 대기
# 📂 볼륨 마운트 (홈 디렉토리 기반 + Poetry 설정)
volumeMounts:
- name: vector-db-storage
mountPath: /home/appuser/vectordb # ✅ PVC 마운트
- name: tmp-volume
mountPath: /tmp
- name: cache-volume
mountPath: /home/appuser/.cache # 전체 캐시 디렉토리
# 🌍 환경변수 설정 - ConfigMap에서 모든 값 가져오기
envFrom:
- configMapRef:
name: vector-api-config
# 🔐 Secret에서 민감한 정보 가져오기
env:
- name: CLAUDE_API_KEY
valueFrom:
secretKeyRef:
name: vector-api-secret
key: CLAUDE_API_KEY
# 🔧 런타임 환경변수 (Poetry 설정을 볼륨으로 이동)
- name: PYTHONPATH
value: "/home/appuser"
- name: HOME
value: "/home/appuser"
- name: USER
value: "appuser"
- name: POETRY_CONFIG_DIR
value: "/home/appuser/.cache/poetry-config" # 볼륨 마운트된 경로로 변경
- name: POETRY_DATA_DIR
value: "/home/appuser/.cache/poetry-data" # 볼륨 마운트된 경로로 변경
- name: POETRY_CACHE_DIR
value: "/home/appuser/.cache/pypoetry/cache"
- name: POETRY_VENV_PATH
value: "/home/appuser/.cache/pypoetry/venvs"
- name: POETRY_NO_INTERACTION
value: "1"
- name: POETRY_VIRTUALENVS_CREATE
value: "true"
- name: POETRY_VIRTUALENVS_IN_PROJECT
value: "false"
# 🔧 성능 최적화 환경변수
- 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
emptyDir:
sizeLimit: 10Gi
- name: tmp-volume
emptyDir:
sizeLimit: 1Gi
- name: cache-volume
emptyDir:
sizeLimit: 2Gi
sizeLimit: 500Mi
# 🔐 이미지 Pull Secret
# 🔐 ACR 접근
imagePullSecrets:
- name: acr-secret
# 🎯 노드 선택 및 배치 설정
# 🎯 노드 선택
nodeSelector:
agentpool: aipool
@@ -230,29 +150,14 @@ spec:
value: "aipool"
effect: "NoSchedule"
# 🔧 Pod 배치 정책
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- vector-api
topologyKey: kubernetes.io/hostname
# 🔧 Pod 설정
restartPolicy: Always
dnsPolicy: ClusterFirst
terminationGracePeriodSeconds: 60
# 🔧 보안 컨텍스트 (Pod 레벨)
# 🔧 Pod 레벨 보안
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
restartPolicy: Always
dnsPolicy: ClusterFirst
terminationGracePeriodSeconds: 30