2.7 KiB
2.7 KiB
Hướng Dẫn Deployment
Thiết Lập Database (Neon)
Tất cả môi trường sử dụng Neon PostgreSQL. Thiết lập một lần trước khi deploy:
- Tạo Neon project tại https://neon.tech
- Tạo branches:
main(dev),staging,production - Lấy connection strings cho mỗi branch
- Cấu hình trong environment variables (xem bên dưới)
Xem Hướng Dẫn Thiết Lập Neon để biết chi tiết.
Local Deployment
# Setup Neon database URL
cp deployments/local/env.local.example deployments/local/.env.local
# Chỉnh sửa .env.local và thêm Neon DATABASE_URL của bạn
# Khởi động services (không cần PostgreSQL container)
cd deployments/local
docker-compose up -d
Staging Deployment
Yêu Cầu
- Quyền truy cập Kubernetes cluster
- kubectl đã cấu hình
- KUBECONFIG đã set
- Neon staging branch đã tạo
- GitHub Secrets đã cấu hình:
NEON_DATABASE_URL_STAGINGKUBECONFIG_STAGING
Thiết Lập Secrets
# Tạo Kubernetes secret
kubectl create secret generic auth-service-secrets \
--from-literal=database-url='postgresql://user:pass@ep-xxx.region.neon.tech/dbname?sslmode=require&pgbouncer=true' \
--from-literal=jwt-secret='your-staging-jwt-secret' \
--from-literal=jwt-refresh-secret='your-staging-refresh-secret' \
-n staging
Deploy
./scripts/deploy/deploy-staging.sh
Hoặc thủ công:
kubectl apply -f deployments/staging/kubernetes/
Lưu ý: Migrations chạy tự động trong CI/CD trước khi deployment.
Production Deployment
Yêu Cầu
- Production Kubernetes cluster
- kubectl đã cấu hình với production context
- Neon production branch đã tạo
- GitHub Secrets đã cấu hình:
NEON_DATABASE_URL_PRODUCTIONKUBECONFIG_PRODUCTION
Thiết Lập Secrets
# Tạo Kubernetes secret
kubectl create secret generic auth-service-secrets \
--from-literal=database-url='postgresql://user:pass@ep-xxx.region.neon.tech/dbname?sslmode=require&pgbouncer=true' \
--from-literal=jwt-secret='your-production-jwt-secret' \
--from-literal=jwt-refresh-secret='your-production-refresh-secret' \
-n production
Deploy
./scripts/deploy/deploy-prod.sh
Lưu ý: Migrations chạy tự động trong CI/CD trước khi deployment (cần approval).
Rollback
kubectl rollout undo deployment/auth-service -n production
Health Checks
- Liveness:
GET /health/live - Readiness:
GET /health/ready - Health:
GET /health
Monitoring
- Prometheus: http://prometheus:9090
- Grafana: http://grafana:3000
- Traefik Dashboard: http://traefik:8080