kubectl "error validating data: ValidationError" in CI
kubectl validates manifests against the resource schema. An unknown field, a wrong type, or a misplaced key fails validation before the object is sent to the API server.
What this error means
A kubectl apply step fails with "error validating data: ValidationError", naming the field that is unknown or of the wrong type and the kind it belongs to.
kubectl
error: error validating "deploy.yaml": error validating data:
ValidationError(Deployment.spec.template.spec.containers[0]):
unknown field "resource" in io.k8s.api.core.v1.Container; if you choose to
ignore these errors, turn validation off with --validate=falseCommon causes
Misspelled or misplaced field
A typo (resource vs resources) or a field at the wrong nesting level fails validation.
Wrong type for a field
A string where a list/int is expected (or vice versa) is rejected by the schema.
Field not in this apiVersion
A field valid in a newer apiVersion is used under an older one.
How to fix it
Fix the named field
- Read the exact path in the error and correct the field name, nesting, or type.
- Validate against the live schema with a server dry-run.
- Do not paper over it with
--validate=false.
Terminal
kubectl apply --dry-run=server -f deploy.yamlHow to prevent it
- Run
kubectl apply --dry-run=serverin CI before the real apply. - Lint manifests (kubeconform/kubeval) against the target cluster version.
- Avoid
--validate=false, which only hides the problem.
Related guides
kubectl "error parsing ... yaml" on apply in CIFix kubectl "error parsing ... yaml" in CI - a manifest is not valid YAML (bad indentation, tabs, or a templa…
kubectl "no matches for kind in version" (apiVersion) in CIFix kubectl "no matches for kind ... in version" in CI - a manifest uses an apiVersion the cluster does not s…
kubectl "the server doesn't have a resource type" (CRD/API version) in CIFix kubectl "the server doesn't have a resource type" in CI - the custom resource's CRD is not installed, or…