# 错误：StatefulSet.apps "my-statefulset" 无效：spec.volumeClaimTemplates[0].metadata.name：无效值："my-pvc"：必须是 DNS 标签（最多 63 个字符，匹配正则 [a-z0-9]([-a-z0-9]*[a-z0-9])?）

- **ID:** `kubernetes/statefulset-pvc-template-name`
- **领域:** kubernetes
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 93%

## 根因

StatefulSet 中的 volumeClaimTemplate 名称包含大写字母、下划线或以非字母数字字符开头，违反了 DNS 标签规则。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kubernetes 1.24 | active | — | — |
| Kubernetes 1.25 | active | — | — |
| Kubernetes 1.26 | active | — | — |

## 解决方案

1. ```
   Use only lowercase letters, numbers, and hyphens: rename 'My_PVC-1' to 'my-pvc-1' and reapply: kubectl apply -f statefulset.yaml
   ```
2. ```
   Validate name before applying: echo 'my-pvc' | grep -E '^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'
   ```

## 无效尝试

- **Changing the PVC name in the template to include underscores or hyphens in wrong positions** — DNS 标签不允许下划线，连字符不能在开头或结尾 (85% 失败率)
- **Adding a random suffix like '-pvc' to the name** — 如果原名称已经无效，添加后缀不会修复根本问题 (60% 失败率)
- **Ignoring the error and reapplying the same YAML** — 错误是确定性的，重新应用不会改变验证逻辑 (99% 失败率)
