K3s 生產級優化 Phase K0 變更: - 新增 startupProbe 到 API/Web/Worker Deployment (60s 啟動時間) - 新增 revisionHistoryLimit: 3 (減少孤立 ReplicaSet) - 新增 09-pdb.yaml (PodDisruptionBudget 保護) - 新增 K3S-OPTIMIZATION-RUNBOOK.md (執行手冊) - 修正 selector 對齊現有 Deployment (app+environment+system) 首席架構師審查: 9.0/10 ✅ Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
113 lines
2.8 KiB
YAML
113 lines
2.8 KiB
YAML
# AWOOOI Backend (FastAPI) Deployment
|
|
# 負責人: CIO
|
|
# 版本: v1.1
|
|
# 日期: 2026-03-20
|
|
# 更新: 2026-03-28 - 新增 startupProbe + revisionHistoryLimit:3 (Phase K0.5/K0.7)
|
|
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: awoooi-api
|
|
namespace: awoooi-prod
|
|
labels:
|
|
app: awoooi-api
|
|
system: awoooi
|
|
environment: prod
|
|
spec:
|
|
replicas: 2
|
|
revisionHistoryLimit: 3
|
|
selector:
|
|
matchLabels:
|
|
app: awoooi-api
|
|
environment: prod
|
|
system: awoooi
|
|
strategy:
|
|
type: RollingUpdate
|
|
rollingUpdate:
|
|
maxSurge: 1
|
|
maxUnavailable: 0
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: awoooi-api
|
|
system: awoooi
|
|
environment: prod
|
|
spec:
|
|
# Phase 7: 使用 RBAC ServiceAccount (最小權限)
|
|
serviceAccountName: awoooi-executor
|
|
automountServiceAccountToken: true
|
|
containers:
|
|
- name: api
|
|
# 映像標籤由 CI/CD 動態注入 (格式: {sha}-{run_id})
|
|
# Harbor 金庫: 110 主機 (192.168.0.110:5000)
|
|
image: 192.168.0.110:5000/library/api:IMAGE_TAG_PLACEHOLDER
|
|
imagePullPolicy: Always
|
|
ports:
|
|
- containerPort: 8000
|
|
name: http
|
|
envFrom:
|
|
- configMapRef:
|
|
name: awoooi-config
|
|
- secretRef:
|
|
name: awoooi-secrets
|
|
resources:
|
|
requests:
|
|
cpu: "200m"
|
|
memory: "512Mi"
|
|
limits:
|
|
cpu: "1"
|
|
memory: "1Gi"
|
|
livenessProbe:
|
|
httpGet:
|
|
path: /api/v1/health
|
|
port: 8000
|
|
initialDelaySeconds: 30
|
|
periodSeconds: 10
|
|
timeoutSeconds: 5
|
|
failureThreshold: 3
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /api/v1/health
|
|
port: 8000
|
|
initialDelaySeconds: 5
|
|
periodSeconds: 5
|
|
timeoutSeconds: 3
|
|
failureThreshold: 3
|
|
# Phase K0.5: Startup Probe (允許最多 60 秒啟動時間)
|
|
startupProbe:
|
|
httpGet:
|
|
path: /api/v1/health
|
|
port: 8000
|
|
initialDelaySeconds: 5
|
|
periodSeconds: 5
|
|
timeoutSeconds: 5
|
|
failureThreshold: 12
|
|
# 反親和性 - 分散到不同節點
|
|
affinity:
|
|
podAntiAffinity:
|
|
preferredDuringSchedulingIgnoredDuringExecution:
|
|
- weight: 100
|
|
podAffinityTerm:
|
|
labelSelector:
|
|
matchLabels:
|
|
app: awoooi-api
|
|
topologyKey: kubernetes.io/hostname
|
|
|
|
---
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: awoooi-api-svc
|
|
namespace: awoooi-prod
|
|
labels:
|
|
app: awoooi-api
|
|
spec:
|
|
type: NodePort
|
|
selector:
|
|
app: awoooi-api
|
|
ports:
|
|
- port: 8000
|
|
targetPort: 8000
|
|
nodePort: 32334
|
|
name: http
|