首页/云/云与容器速查/Deployment 与滚动更新
本包目录(340 条)
云基础概念44 条计算与存储56 条网络与安全组33 条容器与 Docker106 条
Kubernetes68 条
容器排障33 条

Deployment 与滚动更新

无状态工作负载的标准控制器:管理 ReplicaSet、驱动滚动更新与回滚。默认 RollingUpdate(maxSurge 25%、maxUnavailable 25%),发布历史默认保留 10 个 revision。

云与容器速查云更新于 2026-10-12
层级Deployment → ReplicaSet → Pod(版本对应一个 RS)
更新策略strategy.type=RollingUpdate/Recreate;maxSurge/maxUnavailable 控制节奏
历史revisionHistoryLimit 默认 10;rollout history/undo 使用
回滚kubectl rollout undo deploy/web --to-revision=N
触发仅 Pod 模板变化触发滚动(改副本数不算发布)

Deployment 示例

Deployment 示例
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  revisionHistoryLimit: 5
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels: { app: web }
  template:
    metadata:
      labels: { app: web }
    spec:
      containers:
        - name: web
          image: registry.example.com/team/web:1.2.3
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet: { path: /healthz, port: 8080 }
            periodSeconds: 5
maxUnavailable: 0 + maxSurge: 1 是『先起新、后停旧』的保守策略:发布期间容量不缩水,代价是峰值多占资源。

易错点

  • selector 与 template 标签不一致:apply 直接报 selector 不匹配
  • 改 selector 的 matchLabels:字段不可变,只能删了重建

数据来源与参考

  • Kubernetes Docs:Deployments
  • Kubernetes Docs:Rolling Update

相关工具

​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌