kubernetes
config_error
ai_generated
true
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%Fix Rate
90%Confidence
1Evidence
2023-07-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Kubernetes 1.24 | active | — | — | — |
| Kubernetes 1.25 | active | — | — | — |
| Kubernetes 1.26 | active | — | — | — |
Root Cause
The volumeClaimTemplate name in a StatefulSet contains uppercase letters, underscores, or starts with a non-alphanumeric character, violating DNS label rules.
generic中文
StatefulSet 中的 volumeClaimTemplate 名称包含大写字母、下划线或以非字母数字字符开头,违反了 DNS 标签规则。
Official Documentation
https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#volume-claim-templatesWorkarounds
-
95% success Use only lowercase letters, numbers, and hyphens: rename 'My_PVC-1' to 'my-pvc-1' and reapply: kubectl apply -f statefulset.yaml
Use only lowercase letters, numbers, and hyphens: rename 'My_PVC-1' to 'my-pvc-1' and reapply: kubectl apply -f statefulset.yaml
-
90% success Validate name before applying: echo 'my-pvc' | grep -E '^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'
Validate name before applying: echo 'my-pvc' | grep -E '^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'
中文步骤
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])?$'
Dead Ends
Common approaches that don't work:
-
Changing the PVC name in the template to include underscores or hyphens in wrong positions
85% fail
DNS 标签不允许下划线,连字符不能在开头或结尾
-
Adding a random suffix like '-pvc' to the name
60% fail
如果原名称已经无效,添加后缀不会修复根本问题
-
Ignoring the error and reapplying the same YAML
99% fail
错误是确定性的,重新应用不会改变验证逻辑