# 错误：验证 "deployment.yaml" 错误：数据验证错误：[ValidationError(Deployment.spec): 在 io.k8s.api.apps.v1.DeploymentSpec 中发现未知字段 "replicas"]；如果选择忽略这些错误，请使用 --validate=false 关闭验证

- **ID:** `kubernetes/kubectl-apply-invalid-yaml-syntax`
- **领域:** kubernetes
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

YAML 清单有拼写错误或错误字段名（例如 'replicas' 而非 'replicas'），导致 API 验证拒绝。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| kubectl v1.28 | active | — | — |
| kubectl v1.29 | active | — | — |
| kubectl v1.30 | active | — | — |

## 解决方案

1. ```
   Correct the typo: change 'replicas' to 'replicas' in deployment.yaml and reapply: `kubectl apply -f deployment.yaml`.
   ```
2. ```
   Use `kubectl explain deployment.spec.replicas` to verify correct field name and structure.
   ```
3. ```
   Validate YAML offline with `kubectl --dry-run=client -f deployment.yaml` before applying.
   ```

## 无效尝试

- **Use --validate=false blindly to bypass validation** — Bypasses validation but the field is still invalid; API server will reject with a different error. (90% 失败率)
- **Rename the field to something else (e.g., 'count')** — Kubernetes API expects exact field names; renaming won't match the schema. (95% 失败率)
- **Delete and recreate the YAML file** — Recreating doesn't fix the typo; same error will occur. (85% 失败率)
