# backend.yaml — AIOps 后端 (Deployment + Service) # ---------------------------------------------------------------------------- # - 镜像 aiops-backend:latest(前端通过 go:embed 内嵌进同一二进制) # - 暴露两个端口: # 8080 = API + WebSocket # 80 = go:embed 前端 (SPA 静态资源) # - 配置: ConfigMap aiops-config 挂载到 /app/configs/config.yaml # - 密码: Secret aiops-secret 以环境变量注入(DB_PASSWORD / JWT_SECRET) # - Service: ClusterIP,对外暴露 80 与 8080 # # 部署: kubectl apply -f backend.yaml # ---------------------------------------------------------------------------- --- apiVersion: apps/v1 kind: Deployment metadata: name: aiops-backend namespace: devops labels: app.kubernetes.io/name: aiops app.kubernetes.io/component: backend spec: replicas: 1 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 selector: matchLabels: app.kubernetes.io/name: aiops app.kubernetes.io/component: backend template: metadata: labels: app.kubernetes.io/name: aiops app.kubernetes.io/component: backend spec: containers: - name: aiops-backend image: aiops-backend:latest imagePullPolicy: IfNotPresent env: # ---- 数据库连接参数(对应 config.yaml 的 ${DB_*} 占位)---- - {name: DB_HOST, value: mysql} - {name: DB_PORT, value: "3306"} - {name: DB_USER, value: aiops} - {name: DB_NAME, value: aiops} - name: DB_PASSWORD valueFrom: secretKeyRef: name: aiops-secret key: database-password # ---- Redis 连接参数(本环境无密码)---- - {name: REDIS_HOST, value: redis} - {name: REDIS_PORT, value: "6379"} - {name: REDIS_PASSWORD, value: ""} # ---- JWT ---- - name: JWT_SECRET valueFrom: secretKeyRef: name: aiops-secret key: jwt-secret - {name: TZ, value: Asia/Shanghai} ports: - {name: api, containerPort: 8080} # API + WebSocket - {name: web, containerPort: 80} # go:embed 前端 resources: requests: cpu: 100m memory: 512Mi limits: cpu: 500m memory: 1Gi livenessProbe: httpGet: path: /health port: api initialDelaySeconds: 20 periodSeconds: 30 timeoutSeconds: 3 failureThreshold: 3 readinessProbe: httpGet: path: /health port: api initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 3 failureThreshold: 3 volumeMounts: - name: config mountPath: /app/configs readOnly: true volumes: - name: config configMap: name: aiops-config --- # Service — 对内暴露 80 (前端) 与 8080 (API) apiVersion: v1 kind: Service metadata: name: aiops-backend namespace: devops labels: app.kubernetes.io/name: aiops app.kubernetes.io/component: backend spec: type: ClusterIP selector: app.kubernetes.io/name: aiops app.kubernetes.io/component: backend ports: - {name: api, port: 8080, targetPort: 8080} - {name: web, port: 80, targetPort: 80}