确保以下工具已安装并配置:
- AWS CLI v2 -
aws configure配置好凭证 - Terraform >= 1.5
- kubectl - Kubernetes 命令行工具
- Helm 3 - Kubernetes 包管理器
- envsubst - 变量替换工具(
gettext包)
可选工具:jq(JSON 处理)、hey / ab(压力测试)
cd terraform
cp terraform.tfvars.example terraform.tfvars
vim terraform.tfvars关键配置项:
project_name = "litellm"
environment = "prod"
aws_region = "us-west-2"
# 域名
litellm_host = "litellm.example.com"
bot_host = "bot.example.com"
# ACM 证书(两阶段部署说明见下方)
acm_certificate_arn = ""
# 可选: 使用已有 VPC
# create_vpc = false
# existing_vpc_id = "vpc-xxx"域名在 Cloudflare 或其他 DNS 服务商时,ACM 无法自动验证,需要两阶段部署:
# terraform.tfvars
acm_certificate_arn = ""terraform init
terraform apply部署完成后:
- 获取 ALB DNS:
kubectl get ingress -n litellm litellm-ingress-api -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' - 在 Cloudflare / DNS 服务商创建 CNAME:
litellm.example.com → <ALB DNS> - 在 AWS ACM 申请证书,选 DNS 验证
- 在 DNS 服务商添加 ACM 给出的 CNAME 验证记录
- 等待证书状态变为 Issued(通常 5-30 分钟)
# terraform.tfvars
acm_certificate_arn = "arn:aws:acm:us-west-2:123456789012:certificate/xxx"terraform applyTerraform 会自动将 HTTP Ingress 替换为 HTTPS Ingress。
# 预览变更
terraform plan
# 执行部署(约 15-20 分钟)
terraform applyTerraform 输出内容:
eks_cluster_name- EKS 集群名litellm_master_key- Master Key(敏感,使用-raw参数获取)ecr_repository_url- ECR 仓库地址kubeconfig_command- 配置 kubectl 的命令
aws eks update-kubeconfig --name litellm-eks-prod --region us-west-2# 检查 Pod 状态
kubectl get pods -n litellm
# 查看 Ingress(获取 ALB DNS)
kubectl get ingress -n litellm
# 健康检查
curl https://litellm.example.com/health/liveliness预期 Pod 状态:
NAME READY STATUS RESTARTS AGE
litellm-xxxxxxxxxx-xxxxx 1/1 Running 0 2m
litellm-xxxxxxxxxx-xxxxx 1/1 Running 0 2m
| 变更类型 | 命令 |
|---|---|
| 更新 LiteLLM 配置(模型、路由) | kubectl apply -k kubernetes/ |
| 更新镜像版本 | 修改 kubernetes/deployment.yaml → kubectl apply -k kubernetes/ |
| 调整副本数 / HPA | 修改 kubernetes/hpa.yaml → kubectl apply -k kubernetes/ |
| 变更基础设施(VPC、EKS) | terraform apply |
如果已有 VPC,可以跳过 VPC 创建:
# terraform.tfvars
create_vpc = false
existing_vpc_id = "vpc-0123456789abcdef0"
existing_public_subnet_ids = ["subnet-aaa", "subnet-bbb"]
existing_private_subnet_ids = ["subnet-ccc", "subnet-ddd"]enable_waf = trueWAF 规则:
AWSManagedRulesCommonRuleSet- SQLi、XSS 防护RateLimitLiteLLM- 2000 req/5min/IPRateLimitBot- 2000 req/5min/IP
enable_cognito = true
cognito_user_pool_arn = "arn:aws:cognito-idp:..."
cognito_user_pool_client_id = "xxxxxx"
cognito_user_pool_domain = "your-domain"启用后,访问 LiteLLM UI (/ui) 需要 Cognito 登录;API 路径 (/v1/*, /key/*) 仍使用 API Key 认证。