最小 Deployment 骨架
最小 Deployment 骨架
apiVersion: apps/v1 # API 组/版本
kind: Deployment # 资源类型
metadata:
name: web
namespace: prod
labels:
app: web
spec:
replicas: 3
selector: # 必须匹配 template 标签
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.25.3
ports:
- containerPort: 80易错点速记
易错点速记
缩进用空格不用 Tab;同一层级缩进必须一致
字符串含特殊字符时加引号(如 '8080'、'yes'、'on')
selector 与 template.labels 不匹配 → 创建被拒
改不可变字段(selector 等)→ 需要删除重建apiVersion 要写「组/版本」(apps/v1),核心资源如 Pod/Service 是 v1;不确定用 kubectl explain 或 api-resources 查。