| 层级 | 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 是『先起新、后停旧』的保守策略:发布期间容量不缩水,代价是峰值多占资源。