AnCao/k8s-deployment.yaml
yanlongqi 53d3ebe318 feat: 优化静态文件服务和部署配置
主要改进:
- 重构静态文件服务: 实现自定义 StaticFileHandler,完善 SPA 路由支持和 Content-Type 处理
- 优化 Docker 构建: 简化前端资源复制逻辑,直接复制整个 dist 目录
- 添加 K8s 部署配置: 包含健康检查探针、资源限制和服务配置
- 前端配置优化: Vite 使用相对路径 base,确保打包后资源路径正确
- 代码清理: 删除已废弃的数据迁移脚本

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 13:12:20 +08:00

124 lines
3.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

kind: Deployment
apiVersion: apps/v1
metadata:
name: ankao
namespace: default
spec:
selector:
matchLabels:
app: ankao
replicas: 1
template:
metadata:
labels:
app: ankao
spec:
imagePullSecrets:
- name: aliyun
containers:
- name: ankao
image: registry.cn-qingdao.aliyuncs.com/yuchat/ankao:0.0.9
env:
- name: DB_HOST
value: pgsql
- name: DB_USERNAME
value: postgres
- name: DB_PASSWORD
value: longqi@1314
- name: AI_BASE_URL
value: http://new-api
- name: AI_API_KEY
value: sk-OKBmOpJx855juSOPU14cWG6Iz87tZQuv3Xg9PiaJYXdHoKcN
- name: AI_MODEL
value: deepseek-v3
ports:
- containerPort: 8080
name: tcp-8080
# 存活探针 - 检测容器是否正在运行
# 如果失败Kubernetes 会重启容器
livenessProbe:
httpGet:
path: /api/health
port: 8080
scheme: HTTP
initialDelaySeconds: 30 # 容器启动后等待30秒再开始探测
periodSeconds: 10 # 每10秒探测一次
timeoutSeconds: 5 # 探测超时时间5秒
successThreshold: 1 # 成功1次即认为成功
failureThreshold: 3 # 连续失败3次后重启容器
# 就绪探针 - 检测容器是否准备好接收流量
# 如果失败,会从 Service 负载均衡中移除
readinessProbe:
httpGet:
path: /api/health
port: 8080
scheme: HTTP
initialDelaySeconds: 10 # 容器启动后等待10秒再开始探测
periodSeconds: 5 # 每5秒探测一次
timeoutSeconds: 3 # 探测超时时间3秒
successThreshold: 1 # 成功1次即认为就绪
failureThreshold: 3 # 连续失败3次后标记为未就绪
# 启动探针 - 检测容器应用是否已经启动(可选)
# 启动探针成功后,存活探针和就绪探针才会接管
startupProbe:
httpGet:
path: /api/health
port: 8080
scheme: HTTP
initialDelaySeconds: 0 # 立即开始探测
periodSeconds: 5 # 每5秒探测一次
timeoutSeconds: 3 # 探测超时时间3秒
successThreshold: 1 # 成功1次即认为启动完成
failureThreshold: 12 # 最多失败12次60秒才判定启动失败
# 资源限制(建议配置)
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
volumeMounts:
- name: timezone
mountPath: /etc/timezone
readOnly: true
- name: localtime
mountPath: /etc/localtime
readOnly: true
volumes:
- name: timezone
hostPath:
path: /etc/timezone
type: File
- name: localtime
hostPath:
path: /etc/localtime
type: File
restartPolicy: Always
---
kind: Service
apiVersion: v1
metadata:
name: ankao
namespace: default
spec:
selector:
app: ankao
ports:
- name: tcp-80
port: 80
targetPort: 8080
type: LoadBalancer
ipFamilyPolicy: PreferDualStack
ipFamilies:
- IPv4
- IPv6