Schema validation versus parsing
A parsed file is not a validated object
A YAML parser can accept a file even if Kubernetes has no matching resource type or the object contains the wrong fields. Think of five checks: parse the text, identify the API type, validate fields and values, pass server authorization and admission, then observe workload behavior. These are distinct checks, not a precise universal ordering of API internals.
Unknown field: valid YAML, wrong API field
This deliberately incorrect excerpt is valid YAML.
spec: restartPolcy: NeverThe Pod API field is restartPolicy, with an extra i. The correction is:
spec: restartPolicy: NeverThese are partial snippets. A strict Kubernetes validation path should reject an unknown Pod field if it reaches that path; an earlier error can prevent the diagnostic. Some modes and resource schemas can allow or drop unknown fields. Do not assume accepting a file proves it was understood.
Duplicate keys are not safe overrides
This example is intentionally invalid as a YAML mapping because the same key appears twice.
metadata: name: catalog-demo name: reports-demoSome loaders silently keep one value, often the last, and lose the other. Reject duplicates before conversion so the intended name cannot be accidentally replaced. Choose one name entry. Strict server validation can detect duplicate fields that actually reach the server, but cannot recover a duplicate already discarded by a client-side parser.
Check value types separately
Annotations expect string values. Compare these partial snippets:
metadata: annotations: example.com/revision: 2metadata: annotations: example.com/revision: "2"Both can parse. The first uses a number where the annotation map expects a string. The second corrects the type. Quoting is not a general fix: a field that expects an integer needs an integer, not a string. A local checker covering only selected fields cannot certify a complete resource.
Use documentation and dry-run in a trusted lab
You can check the field documentation with kubectl explain when a trusted cluster is configured. The following commands are static examples, not executed results. Prerequisites: reviewed compatible client/server, approved disposable cluster, trusted dedicated kubeconfig, existing book-lab namespace, sufficient permissions, and a reviewed local file. Run nothing against an unknown context.
kubectl --kubeconfig=./bm-lab.conf --context=bm-lab --namespace=book-lab explain pod.spec.restartPolicykubectl --kubeconfig=./bm-lab.conf --context=bm-lab --namespace=book-lab apply --dry-run=server --validate=strict -f ./lab-pod.yamllab-pod.yaml denotes a separately reviewed lab file; the chapter fixture is not suitable for running a workload. Server dry-run sends a real API request, which is processed through the relevant server validation and admission paths without persisting the requested object. Authorization and admission can still reject it. Client dry-run previews the request object without submitting the mutation, but may need discovery or validation information from a server. Neither proves image availability, scheduling or actual readiness. Do not remove the dry-run flag to get past an error.
Diagnose one layer at a time
For malformed indentation, repair the text. For duplicate keys, choose one unambiguous value. For an unknown field, check the selected API type and field spelling. For a wrong type, compare the value with the API definition. For a policy rejection, read the admission message and follow the approved policy. For a Pod that never becomes healthy, inspect its observations and events; syntax alone cannot solve it.
This package supplies offline valid-structure and negative fixtures with documented expectations. Local checks cover YAML parsing and a small set of field rules only. They are not the upstream OpenAPI schema or a server test. Related reference: Schema validation versus parsing.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Schema validation versus parsing — knowledge check
Apply the lesson concepts to original offline scenarios.
A YAML parser accepts `restartPolcy`. What should you check next?
Why reject repeated keys before converting YAML?
What type does an annotation value require?
Which statement about server dry-run is correct?
What does a successful syntax check prove?