Skip to content
Latchkey

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=false

Common 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

  1. Read the exact path in the error and correct the field name, nesting, or type.
  2. Validate against the live schema with a server dry-run.
  3. Do not paper over it with --validate=false.
Terminal
kubectl apply --dry-run=server -f deploy.yaml

How to prevent it

  • Run kubectl apply --dry-run=server in CI before the real apply.
  • Lint manifests (kubeconform/kubeval) against the target cluster version.
  • Avoid --validate=false, which only hides the problem.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →