- 在 Worker 中引入轻量级 HTTP 服务器,支持健康检查和就绪检查端点。 - 在 Kubernetes 和 Docker 配置中新增健康检查探针,提升服务稳定性。 - 更新依赖,引入 `aiohttp` 用于健康检查服务。 - 优化部署配置,调整 Redis 主机配置和镜像地址以适配新环境。
212 lines
4.7 KiB
YAML
212 lines
4.7 KiB
YAML
# Kubernetes 部署配置
|
||
# 包含:ConfigMap、API Deployment、Worker Deployment、Redis Deployment
|
||
|
||
---
|
||
# ConfigMap - 共享配置
|
||
apiVersion: v1
|
||
kind: ConfigMap
|
||
metadata:
|
||
name: functional-scaffold-config
|
||
labels:
|
||
app: functional-scaffold
|
||
data:
|
||
APP_ENV: "production"
|
||
LOG_LEVEL: "INFO"
|
||
LOG_FORMAT: "json"
|
||
METRICS_ENABLED: "true"
|
||
# Redis 配置(指向集群内 Redis 服务)
|
||
REDIS_HOST: "functional-scaffold-redis"
|
||
REDIS_PORT: "6379"
|
||
REDIS_DB: "0"
|
||
# 异步任务配置
|
||
MAX_CONCURRENT_JOBS: "10"
|
||
JOB_RESULT_TTL: "1800"
|
||
WEBHOOK_MAX_RETRIES: "3"
|
||
WEBHOOK_TIMEOUT: "10"
|
||
# Worker 配置
|
||
WORKER_POLL_INTERVAL: "1.0"
|
||
JOB_QUEUE_KEY: "job:queue"
|
||
JOB_CONCURRENCY_KEY: "job:concurrency"
|
||
JOB_LOCK_TTL: "300"
|
||
JOB_MAX_RETRIES: "3"
|
||
JOB_EXECUTION_TIMEOUT: "300"
|
||
|
||
---
|
||
# API Deployment - HTTP 服务
|
||
apiVersion: apps/v1
|
||
kind: Deployment
|
||
metadata:
|
||
name: functional-scaffold-api
|
||
labels:
|
||
app: functional-scaffold
|
||
component: api
|
||
spec:
|
||
replicas: 3
|
||
selector:
|
||
matchLabels:
|
||
app: functional-scaffold
|
||
component: api
|
||
template:
|
||
metadata:
|
||
labels:
|
||
app: functional-scaffold
|
||
component: api
|
||
spec:
|
||
containers:
|
||
- name: api
|
||
image: functional-scaffold:latest
|
||
imagePullPolicy: IfNotPresent
|
||
ports:
|
||
- containerPort: 8000
|
||
name: http
|
||
env:
|
||
- name: RUN_MODE
|
||
value: "api"
|
||
envFrom:
|
||
- configMapRef:
|
||
name: functional-scaffold-config
|
||
resources:
|
||
requests:
|
||
memory: "256Mi"
|
||
cpu: "250m"
|
||
limits:
|
||
memory: "512Mi"
|
||
cpu: "500m"
|
||
livenessProbe:
|
||
httpGet:
|
||
path: /healthz
|
||
port: 8000
|
||
initialDelaySeconds: 10
|
||
periodSeconds: 30
|
||
timeoutSeconds: 3
|
||
failureThreshold: 3
|
||
readinessProbe:
|
||
httpGet:
|
||
path: /readyz
|
||
port: 8000
|
||
initialDelaySeconds: 5
|
||
periodSeconds: 10
|
||
timeoutSeconds: 3
|
||
failureThreshold: 3
|
||
|
||
---
|
||
# Worker Deployment - 异步任务处理
|
||
apiVersion: apps/v1
|
||
kind: Deployment
|
||
metadata:
|
||
name: functional-scaffold-worker
|
||
labels:
|
||
app: functional-scaffold
|
||
component: worker
|
||
spec:
|
||
replicas: 2
|
||
selector:
|
||
matchLabels:
|
||
app: functional-scaffold
|
||
component: worker
|
||
template:
|
||
metadata:
|
||
labels:
|
||
app: functional-scaffold
|
||
component: worker
|
||
spec:
|
||
containers:
|
||
- name: worker
|
||
image: functional-scaffold:latest
|
||
imagePullPolicy: IfNotPresent
|
||
env:
|
||
- name: RUN_MODE
|
||
value: "worker"
|
||
envFrom:
|
||
- configMapRef:
|
||
name: functional-scaffold-config
|
||
resources:
|
||
requests:
|
||
memory: "256Mi"
|
||
cpu: "250m"
|
||
limits:
|
||
memory: "512Mi"
|
||
cpu: "500m"
|
||
# Worker 现在有 HTTP 健康检查端点
|
||
ports:
|
||
- containerPort: 8000
|
||
name: http
|
||
livenessProbe:
|
||
httpGet:
|
||
path: /healthz
|
||
port: 8000
|
||
initialDelaySeconds: 10
|
||
periodSeconds: 30
|
||
timeoutSeconds: 3
|
||
failureThreshold: 3
|
||
readinessProbe:
|
||
httpGet:
|
||
path: /readyz
|
||
port: 8000
|
||
initialDelaySeconds: 5
|
||
periodSeconds: 10
|
||
timeoutSeconds: 3
|
||
failureThreshold: 3
|
||
|
||
---
|
||
# Redis Deployment - 任务队列和状态存储
|
||
apiVersion: apps/v1
|
||
kind: Deployment
|
||
metadata:
|
||
name: functional-scaffold-redis
|
||
labels:
|
||
app: functional-scaffold
|
||
component: redis
|
||
spec:
|
||
replicas: 1
|
||
selector:
|
||
matchLabels:
|
||
app: functional-scaffold
|
||
component: redis
|
||
template:
|
||
metadata:
|
||
labels:
|
||
app: functional-scaffold
|
||
component: redis
|
||
spec:
|
||
containers:
|
||
- name: redis
|
||
image: redis:7-alpine
|
||
ports:
|
||
- containerPort: 6379
|
||
name: redis
|
||
command:
|
||
- redis-server
|
||
- --appendonly
|
||
- "yes"
|
||
resources:
|
||
requests:
|
||
memory: "128Mi"
|
||
cpu: "100m"
|
||
limits:
|
||
memory: "256Mi"
|
||
cpu: "200m"
|
||
livenessProbe:
|
||
exec:
|
||
command:
|
||
- redis-cli
|
||
- ping
|
||
initialDelaySeconds: 5
|
||
periodSeconds: 10
|
||
timeoutSeconds: 3
|
||
failureThreshold: 3
|
||
readinessProbe:
|
||
exec:
|
||
command:
|
||
- redis-cli
|
||
- ping
|
||
initialDelaySeconds: 5
|
||
periodSeconds: 5
|
||
timeoutSeconds: 3
|
||
failureThreshold: 3
|
||
volumeMounts:
|
||
- name: redis-data
|
||
mountPath: /data
|
||
volumes:
|
||
- name: redis-data
|
||
emptyDir: {} |