概述本文总结生产环境运行 Kubernetes 的关键落地点,包括资源配额、弹性伸缩、健康探针、滚动升级与中断预算,附带可直接应用的配置示例。资源请求与限制(已验证)`requests` 表示调度与资源预留;`limits` 表示硬上限。应满足 `requests ≤ limits`。QoS 类别:`Guaranteed`:所有容器均设置且 `requests = limits`。`Burstable`:设置了 `requests` 但不满足 `Guaranteed`。`BestEffort`:未设置 `requests` 与 `limits`。健康探针与就绪配置 `livenessProbe` 与 `readinessProbe`,确保故障自愈与流量只进入就绪副本。readinessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 5 periodSeconds: 10 livenessProbe: httpGet: path: /livez port: 8080 initialDelaySeconds: 15 periodSeconds: 20 弹性伸缩(HPA 示例)apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: myapp-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: myapp minReplicas: 2 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 60 确保安装 Metrics Server 以提供资源度量。发布与升级使用滚动更新,观察副本就绪:kubectl rollout status deployment/myapp 设置 `maxUnavailable` 与 `maxSurge` 控制发布风险;必要时使用 `canary` 或 `blue/green`。中断预算与调度配置 `PodDisruptionBudget`(PDB)保障最小可用副本数:apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: myapp-pdb spec: minAvailable: 2 selector: matchLabels: app: myapp 使用亲和/反亲和与拓扑约束实现跨节点高可用;关键工作负载可设置优先级与抢占策略。监控与告警采集应用与集群指标(Prometheus/Grafana),配置关键 SLO 告警(错误率、延迟、可用副本)。捕获 OOMKill 与重启原因,调整资源曲线与 GC 策略。注意事项资源设置以真实负载为基线,避免过度保守导致资源浪费或过度激进引发稳定性问题。变更采用分批与回滚策略,保留上一个稳定版本的镜像与配置。

发表评论 取消回复