Files
ljwx-health/ljwx-bigscreen/k8s/prod/deployment.yaml
T
2025-12-17 11:18:26 +01:00

145 lines
3.5 KiB
YAML

apiVersion: apps/v1
kind: Deployment
metadata:
name: ljwx-bigscreen
namespace: ljwx-health
labels:
app: ljwx-bigscreen
env: prod
spec:
replicas: 3 # 生产环境默认3个副本
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
selector:
matchLabels:
app: ljwx-bigscreen
env: prod
template:
metadata:
labels:
app: ljwx-bigscreen
env: prod
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "5001"
prometheus.io/path: "/metrics"
spec:
affinity: # Pod反亲和性,确保分布在不同节点
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- ljwx-bigscreen
topologyKey: kubernetes.io/hostname
containers:
- name: ljwx-bigscreen
image: 173.212.254.252:5000/ljwx-health/ljwx-bigscreen:latest
ports:
- containerPort: 5001
name: http
env:
- name: MYSQL_HOST
valueFrom:
secretKeyRef:
name: ljwx-db-secret
key: host
- name: MYSQL_PORT
value: "3306"
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: ljwx-db-secret
key: username
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: ljwx-db-secret
key: password
- name: MYSQL_DATABASE
value: "test"
- name: APP_PORT
value: "5001"
- name: REDIS_HOST
valueFrom:
configMapKeyRef:
name: ljwx-config
key: redis.host
- name: REDIS_PORT
value: "6379"
- name: ENV
value: "production"
resources:
requests:
memory: "512Mi"
cpu: "200m"
limits:
memory: "1Gi"
cpu: "1000m"
livenessProbe:
tcpSocket:
port: 5001
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 10
failureThreshold: 3
readinessProbe:
tcpSocket:
port: 5001
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 5
failureThreshold: 3
startupProbe: # 启动探针,给应用更多启动时间
tcpSocket:
port: 5001
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 10
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: ljwx-bigscreen-hpa
namespace: ljwx-health
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: ljwx-bigscreen
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
behavior: # 扩缩容行为配置
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Percent
value: 100
periodSeconds: 15
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60