Files
kami_apple_exchage/backend/deploy/k8s/deployment.yaml
danial 108a8810e6 refactor: migrate to Apple Exchange backend architecture
Remove distributed crawler system and refactor backend to focus on Apple Gift Card Exchange functionality. Update deployment configurations and dependencies accordingly.
2025-08-26 23:39:47 +08:00

350 lines
9.3 KiB
YAML

# API服务部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: apple-exchange-api
namespace: apple-exchange
labels:
app: apple-exchange-api
component: api
version: v2.0.0
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
selector:
matchLabels:
app: apple-exchange-api
component: api
template:
metadata:
labels:
app: apple-exchange-api
component: api
version: v2.0.0
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
prometheus.io/path: "/api/v1/health/metrics"
spec:
containers:
- name: api
image: apple-exchange-api:latest
imagePullPolicy: Always
ports:
- containerPort: 8000
name: http
env:
- name: SERVICE_TYPE
value: "api"
- name: DATABASE_URL
value: "postgresql+asyncpg://$(DATABASE_USER):$(DATABASE_PASSWORD)@$(DATABASE_HOST):$(DATABASE_PORT)/$(DATABASE_NAME)"
- name: REDIS_URL
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/$(REDIS_DB)"
- name: CELERY_BROKER_URL
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/0"
- name: CELERY_RESULT_BACKEND
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/1"
- name: SCREENSHOT_DIR
value: "/app/screenshots"
- name: LOG_DIR
value: "/app/logs"
envFrom:
- configMapRef:
name: apple-exchange-config
- secretRef:
name: apple-exchange-secret
resources:
requests:
memory: "512Mi"
cpu: "500m"
limits:
memory: "1Gi"
cpu: "1000m"
livenessProbe:
httpGet:
path: /api/v1/health/liveness
port: 8000
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /api/v1/health/readiness
port: 8000
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
startupProbe:
httpGet:
path: /api/v1/health/startup
port: 8000
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 30
volumeMounts:
- name: logs
mountPath: /app/logs
- name: screenshots
mountPath: /app/screenshots
- name: shared
mountPath: /app/shared
volumes:
- name: logs
persistentVolumeClaim:
claimName: apple-exchange-logs-pvc
- name: screenshots
persistentVolumeClaim:
claimName: apple-exchange-screenshots-pvc
- name: shared
persistentVolumeClaim:
claimName: apple-exchange-shared-pvc
restartPolicy: Always
---
# Celery Worker部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: apple-exchange-worker
namespace: apple-exchange
labels:
app: apple-exchange-worker
component: worker
version: v2.0.0
spec:
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 2
selector:
matchLabels:
app: apple-exchange-worker
component: worker
template:
metadata:
labels:
app: apple-exchange-worker
component: worker
version: v2.0.0
annotations:
prometheus.io/scrape: "false"
spec:
containers:
- name: worker
image: apple-exchange-api:latest
imagePullPolicy: Always
env:
- name: SERVICE_TYPE
value: "worker"
- name: DATABASE_URL
value: "postgresql+asyncpg://$(DATABASE_USER):$(DATABASE_PASSWORD)@$(DATABASE_HOST):$(DATABASE_PORT)/$(DATABASE_NAME)"
- name: REDIS_URL
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/$(REDIS_DB)"
- name: CELERY_BROKER_URL
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/0"
- name: CELERY_RESULT_BACKEND
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/1"
- name: CELERY_CONCURRENCY
value: "2"
- name: CELERY_MAX_TASKS_PER_CHILD
value: "1000"
- name: CELERY_PREFETCH_MULTIPLIER
value: "1"
- name: SCREENSHOT_DIR
value: "/app/screenshots"
- name: LOG_DIR
value: "/app/logs"
- name: PLAYWRIGHT_BROWSERS_PATH
value: "/app/playwright-browsers"
envFrom:
- configMapRef:
name: apple-exchange-config
- secretRef:
name: apple-exchange-secret
resources:
requests:
memory: "1Gi"
cpu: "500m"
limits:
memory: "2Gi"
cpu: "1500m"
livenessProbe:
exec:
command:
- python
- -c
- "from app.core.celery_app import get_celery_app; app = get_celery_app(); print('Worker healthy')"
initialDelaySeconds: 60
periodSeconds: 60
timeoutSeconds: 30
failureThreshold: 3
readinessProbe:
exec:
command:
- python
- -c
- "from app.core.celery_app import get_celery_app; app = get_celery_app(); print('Worker ready')"
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 15
successThreshold: 1
failureThreshold: 3
volumeMounts:
- name: logs
mountPath: /app/logs
- name: screenshots
mountPath: /app/screenshots
- name: shared
mountPath: /app/shared
- name: playwright-browsers
mountPath: /app/playwright-browsers
volumes:
- name: logs
persistentVolumeClaim:
claimName: apple-exchange-logs-pvc
- name: screenshots
persistentVolumeClaim:
claimName: apple-exchange-screenshots-pvc
- name: shared
persistentVolumeClaim:
claimName: apple-exchange-shared-pvc
- name: playwright-browsers
emptyDir:
sizeLimit: 2Gi
restartPolicy: Always
---
# Celery Beat调度器部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: apple-exchange-beat
namespace: apple-exchange
labels:
app: apple-exchange-beat
component: beat
version: v2.0.0
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: apple-exchange-beat
component: beat
template:
metadata:
labels:
app: apple-exchange-beat
component: beat
version: v2.0.0
spec:
containers:
- name: beat
image: apple-exchange-api:latest
imagePullPolicy: Always
env:
- name: SERVICE_TYPE
value: "beat"
- name: DATABASE_URL
value: "postgresql+asyncpg://$(DATABASE_USER):$(DATABASE_PASSWORD)@$(DATABASE_HOST):$(DATABASE_PORT)/$(DATABASE_NAME)"
- name: REDIS_URL
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/$(REDIS_DB)"
- name: CELERY_BROKER_URL
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/0"
- name: CELERY_RESULT_BACKEND
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/1"
envFrom:
- configMapRef:
name: apple-exchange-config
- secretRef:
name: apple-exchange-secret
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
volumeMounts:
- name: logs
mountPath: /app/logs
- name: beat-schedule
mountPath: /app/data
volumes:
- name: logs
persistentVolumeClaim:
claimName: apple-exchange-logs-pvc
- name: beat-schedule
emptyDir: {}
restartPolicy: Always
---
# Celery Flower监控部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: apple-exchange-flower
namespace: apple-exchange
labels:
app: apple-exchange-flower
component: flower
version: v2.0.0
spec:
replicas: 1
selector:
matchLabels:
app: apple-exchange-flower
component: flower
template:
metadata:
labels:
app: apple-exchange-flower
component: flower
version: v2.0.0
spec:
containers:
- name: flower
image: apple-exchange-api:latest
imagePullPolicy: Always
ports:
- containerPort: 5555
name: flower
env:
- name: SERVICE_TYPE
value: "flower"
- name: REDIS_URL
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/$(REDIS_DB)"
- name: CELERY_BROKER_URL
value: "redis://$(REDIS_HOST):$(REDIS_PORT)/0"
envFrom:
- configMapRef:
name: apple-exchange-config
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "200m"
livenessProbe:
httpGet:
path: /
port: 5555
initialDelaySeconds: 30
periodSeconds: 30
readinessProbe:
httpGet:
path: /
port: 5555
initialDelaySeconds: 10
periodSeconds: 10
restartPolicy: Always