# api-gateway Deployment + Service 骨架 # 生产环境请通过 Helm Chart 管理,此处仅作骨架参考 apiVersion: apps/v1 kind: Deployment metadata: name: api-gateway namespace: edu-services labels: app.kubernetes.io/name: api-gateway app.kubernetes.io/part-of: edu-platform app.kubernetes.io/component: gateway spec: replicas: 2 selector: matchLabels: app.kubernetes.io/name: api-gateway strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 template: metadata: labels: app.kubernetes.io/name: api-gateway app.kubernetes.io/part-of: edu-platform app.kubernetes.io/component: gateway annotations: prometheus.io/scrape: "true" prometheus.io/port: "8080" prometheus.io/path: "/metrics" spec: containers: - name: api-gateway image: edu/api-gateway:latest # 生产请固定 tag,避免 latest imagePullPolicy: IfNotPresent ports: - name: http containerPort: 8080 protocol: TCP # 存活探针:失败触发重启 livenessProbe: httpGet: path: /healthz port: http initialDelaySeconds: 15 periodSeconds: 20 timeoutSeconds: 3 failureThreshold: 3 # 就绪探针:失败从 Service Endpoints 摘除 readinessProbe: httpGet: path: /readyz port: http initialDelaySeconds: 5 periodSeconds: 10 timeoutSeconds: 3 failureThreshold: 2 resources: requests: cpu: "250m" memory: "256Mi" limits: cpu: "1000m" memory: "1Gi" env: # 从 ConfigMap 引用非敏感配置 - name: NODE_ENV valueFrom: configMapKeyRef: name: api-gateway-config key: NODE_ENV - name: LOG_LEVEL valueFrom: configMapKeyRef: name: api-gateway-config key: LOG_LEVEL - name: MYSQL_HOST valueFrom: configMapKeyRef: name: api-gateway-config key: MYSQL_HOST # 从 Secret 引用敏感配置 - name: MYSQL_PASSWORD valueFrom: secretKeyRef: name: api-gateway-secret key: MYSQL_PASSWORD - name: JWT_SECRET valueFrom: secretKeyRef: name: api-gateway-secret key: JWT_SECRET - name: REDIS_PASSWORD valueFrom: secretKeyRef: name: api-gateway-secret key: REDIS_PASSWORD # 生产建议挂载 /tmp 并设置 readOnlyRootFilesystem: true securityContext: runAsNonRoot: true runAsUser: 1000 allowPrivilegeEscalation: false capabilities: drop: ["ALL"] --- # api-gateway Service(ClusterIP) apiVersion: v1 kind: Service metadata: name: api-gateway namespace: edu-services labels: app.kubernetes.io/name: api-gateway app.kubernetes.io/part-of: edu-platform app.kubernetes.io/component: gateway spec: type: ClusterIP selector: app.kubernetes.io/name: api-gateway ports: - name: http port: 8080 targetPort: http protocol: TCP