kubectl apply rejects a manifest with strict decoding error: unknown field
Your error
Error from server (BadRequest): error when creating "deploy.yaml": Deployment in version "v1" cannot be handled as a Deployment: strict decoding error: unknown field "spec.template.metadata.containers"2 more lines it can showFix it fast
Most common cause, 1 of 3A key sits under the wrong parent, or is spelled wrong
Move the block to the parent that kubectl explain shows for it, or correct the spelling, then run the server dry run again.
spec:
template:
metadata:
labels:
app: web
spec: # containers belong here, not under metadata
containers:
- name: web
image: nginx:1.29Short answer
strict decoding error: unknown field means the API server met a key that its schema for that object lacks, and kubectl's default strict validation rejects the request. The key is misplaced or misspelled, newer than your cluster, or missing from an old CustomResourceDefinition. Fix whatever the quoted path points to. Applies to Kubernetes 1.27 to 1.37.
Which cause do you have?
Send the manifest to the server without saving it, so every unknown path is listed in one go, and note the server's version. The quoted path plus the version tell the causes apart.
kubectl apply --dry-run=server -f deploy.yaml
kubectl versionThen find the line you see in this list and open its fix:
- 1A key sits under the wrong parent, or is spelled wrong
The path joins real field names in an impossible place, such as spec.template.metadata.containers or spec.limits, or the last word has a typo - 2The field is newer than the cluster's API server
The YAML matches current Kubernetes docs, the path ends in a recently added field such as initContainers[0].restartPolicy, and kubectl version shows an older Server Version - 3A custom resource uses a field the installed CRD does not define yet
The kind is a custom resource (cert-manager, Prometheus Operator and similar), the operator or chart was upgraded recently, and the unknown path is a new option from its changelog
What does the error look like?
Error from server (BadRequest): error when creating "deploy.yaml": Deployment in version "v1" cannot be handled as a Deployment: strict decoding error: unknown field "spec.template.metadata.containers"Job in version "v1" cannot be handled as a Job: strict decoding error: unknown field "spec.template.spec.initContainers[0].restartPolicy"strict decoding error: unknown field
Cause 1 of 3
A key sits under the wrong parent, or is spelled wrong
You seeThe path joins real field names in an impossible place, such as spec.template.metadata.containers or spec.limits, or the last word has a typo
Check
Most unknown field errors come from indentation. In the dotnet-docker sample that produced unknown field spec.template.metadata.containers, containers and volumes had been placed under template.metadata, where Kubernetes has no such keys, instead of under template.spec. A spelling slip such as imagePullPolicyy fails the same way.
kubectl explain deployment.spec.template.spec.containersFix
Move the block to the parent that kubectl explain shows for it, or correct the spelling, then run the server dry run again. Each path it still prints is another key to move.
spec:
template:
metadata:
labels:
app: web
spec: # containers belong here, not under metadata
containers:
- name: web
image: nginx:1.29Verify
The dry run completes and no BadRequest line is printed.
kubectl apply --dry-run=server -f deploy.yamlConfirmed by github.com
Cause 2 of 3
The field is newer than the cluster's API server
You seeThe YAML matches current Kubernetes docs, the path ends in a recently added field such as initContainers[0].restartPolicy, and kubectl version shows an older Server Version
Check
An API server only knows the fields of its own release. The Kubernetes website issue for the sidecar examples shows exactly this: a Job using restartPolicy on an init container failed on a 1.27.3 cluster, because native sidecar containers first appeared in 1.28 and have been stable only since 1.33. Docs for the newest release describe fields an older cluster rejects.
kubectl version
kubectl explain pod.spec.initContainers.restartPolicyFix
Upgrade the cluster to a release that has the field, or write the manifest for the version you run, for example an ordinary sidecar in containers instead of a restartable init container. Use the docs version selector to read the pages for your cluster's minor version.
kubectl version # Server Version: v1.27.x
# either upgrade the control plane to 1.33 or later,
# or remove restartPolicy: Always from initContainers and run the helper in containersVerify
kubectl explain now documents the field (after an upgrade), or the reworked manifest passes the server dry run.
kubectl apply --dry-run=server -f job.yamlConfirmed by github.com
Cause 3 of 3
A custom resource uses a field the installed CRD does not define yet
You seeThe kind is a custom resource (cert-manager, Prometheus Operator and similar), the operator or chart was upgraded recently, and the unknown path is a new option from its changelog
Check
Strict validation also applies to custom resources, whose schema comes from the CustomResourceDefinition stored in the cluster. Helm installs a chart's CRDs once and skips them afterwards; its docs state that upgrading or deleting CRDs is not supported. After a chart upgrade the CRD can stay old while your manifests already use the new field.
kubectl explain <kind>.spec --recursiveFix
Apply the CRDs that ship with the chart version you now run, then apply your custom resource again. Read the operator's upgrade notes first, since some releases need a migration step.
helm show crds <repo>/<chart> --version <chart-version> | kubectl apply --server-side -f -
kubectl apply -f my-resource.yamlVerify
kubectl explain on the custom kind lists the new field and the resource is created.
kubectl explain <kind>.specConfirmed by helm.sh
How do I stop it coming back?
- Never switch to --validate=ignore to get past this: the server then drops the unknown key without a word, and the setting you wrote silently does nothing.
- Pin the Kubernetes docs version you copy examples from to your cluster's minor version.
- Make CRD upgrades an explicit step in the runbook for every Helm chart that ships CRDs.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Dispatch Pro.