kubernetes
config_error
ai_generated
true
错误:StatefulSet.apps "my-statefulset" 无效:spec.volumeClaimTemplates[0].metadata.name:无效值:"my-pvc":必须是 DNS 标签(最多 63 个字符,匹配正则 [a-z0-9]([-a-z0-9]*[a-z0-9])?)
Error: StatefulSet.apps "my-statefulset" is invalid: spec.volumeClaimTemplates[0].metadata.name: Invalid value: "my-pvc": must be a DNS label (at most 63 characters, matching regex [a-z0-9]([-a-z0-9]*[a-z0-9])?)
ID: kubernetes/statefulset-pvc-template-name
93%修复率
90%置信度
1证据数
2023-07-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Kubernetes 1.24 | active | — | — | — |
| Kubernetes 1.25 | active | — | — | — |
| Kubernetes 1.26 | active | — | — | — |
根因分析
StatefulSet 中的 volumeClaimTemplate 名称包含大写字母、下划线或以非字母数字字符开头,违反了 DNS 标签规则。
English
The volumeClaimTemplate name in a StatefulSet contains uppercase letters, underscores, or starts with a non-alphanumeric character, violating DNS label rules.
官方文档
https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#volume-claim-templates解决方案
-
Use only lowercase letters, numbers, and hyphens: rename 'My_PVC-1' to 'my-pvc-1' and reapply: kubectl apply -f statefulset.yaml
-
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
85% 失败
DNS 标签不允许下划线,连字符不能在开头或结尾
-
Adding a random suffix like '-pvc' to the name
60% 失败
如果原名称已经无效,添加后缀不会修复根本问题
-
Ignoring the error and reapplying the same YAML
99% 失败
错误是确定性的,重新应用不会改变验证逻辑