Skip to content

strict decoding error: unknown field – a typo in the resource

Kubernetestested on kubeadm, Kubernetes v1.37.3

When creating a resource, the API server reports an unknown field. That is a good thing: without strict field validation it would have silently removed the field, and the object would look valid without doing what was intended.

Symptom

printf 'apiVersion: plattform.lab/v1beta1\nkind: Umgebung\nmetadata:\n  name: tippfehler\n  namespace: team-blue\nspec:\n  team: blue\n  stundne: 4\n' \
  | k apply -f -
Error from server (BadRequest): error when creating "STDIN": Umgebung in version "v1beta1" cannot be handled as a Umgebung: strict decoding error: unknown field "spec.stundne"

Two letters are swapped in the field stunden ("hours") – stundne does not exist in the CRD's schema.

Diagnosis

Create the same object without field validation and look at what gets stored.

printf 'apiVersion: plattform.lab/v1beta1\nkind: Umgebung\nmetadata:\n  name: tippfehler\n  namespace: team-blue\nspec:\n  team: blue\n  stundne: 4\n' \
  | k apply --validate=false -f -
k -n team-blue get umg tippfehler -o jsonpath='{.spec}{"\n"}'
umgebung.plattform.lab/tippfehler created
{"datenbank":false,"groesse":"S","stunden":24,"team":"blue"}

Causes

unknown fieldField not in the schema

Since version 1.27, kubectl sends fieldValidation=Strict. The server then rejects every field the schema does not know.

stunden 24Without validation the field vanishes silently

Without strict validation, the server removes unknown fields (pruning), and the default stunden 24 applies instead of the intended 4.

Fix

Correct the field name and delete the test object again.
k -n team-blue delete umg tippfehler
umgebung.plattform.lab "tippfehler" deleted from team-blue namespace

Don't: Set --validate=false to make the error go away. Always use strict field validation in your own tools and pipelines.

▶
Break it yourself and find it – free
CNPE hands-on, Day 7: platform APIs with CRDs – schema, CEL rules, status subresource and versions.
Go to day 7 →

FAQ

Why does my own tool not catch the typo?

Clients without fieldValidation=Strict get no error – the server silently removes the field. Set the parameter in your own clients.

And if several rules are violated?

The server reports all schema errors at once. CEL rules only run once the simple checks have passed.

Related error patterns

More