apiVersion, kind, and metadata; resource types that require a configuration include a spec section (for example Pods and Deployments).
Top-level fields (overview)
Below is a concise summary of the common top-level fields you will see in most Kubernetes manifests.Always use the API version and fields appropriate for the object you are creating. Consult the Kubernetes API reference for the exact schema for each resource.
Minimal Pod YAML example
This is a minimal but complete Pod manifest that runs a single nginx container. Note the four top-level fields and correct indentation.apiVersion: v1— Pods are in the core API group (v1).kind: Pod— Declares the resource type.metadata.name— Unique name for the Pod within a namespace.metadata.labels— Key/value pairs for selection and grouping (example:app: myapp).spec.containers— A list of container definitions. Each item is a mapping withname,image, and optional settings (ports, env, resources, etc.).image— The image name (from Docker Hub or another registry); include a tag if you need a specific version (for examplenginx:1.21).
Common YAML / indentation pitfalls
- YAML is whitespace-sensitive. Child properties must be indented more than their parent; sibling keys must align at the same indentation level.
- Ensure that
nameandlabelsare siblings undermetadata(same indentation), and that keys likeappare children oflabels(more indented). - Only include valid fields supported by the API for the given section. Unknown keys may be ignored or cause the API to reject the manifest.
Incorrect indentation, invalid field names, or the wrong
apiVersion are common causes of manifest errors. Always validate YAML formatting and the resource schema before applying.Create and inspect the Pod
- Save the YAML to a file, for example
pod-definition.yaml. - Create the Pod:
- Useful commands to inspect and debug:
Examples:
describe output shows events (image pull errors, container start failures), labels, IP addresses, and other runtime details helpful for debugging.
Best practices & checklist
- Use explicit
apiVersionvalues that match your cluster version. For Pods, usev1. - Add
labelsso you can select and manage objects later (Deployments, Services, NetworkPolicies). - Specify container
resources(requests/limits) in production to help scheduler decisions. - Lock container images to a specific tag in production (
nginx:1.21), and scan images for vulnerabilities. - Validate manifests with
kubectl apply --dry-run=client -f pod-definition.yamlor a linter likekube-scoreorkubeval.
Links and references
Summary
- Kubernetes manifests typically include
apiVersion,kind,metadata, and, where applicable,spec. - Use
spec.containers(a list) to declare one or more containers in a Pod. - Labels are important for selection and grouping of objects later.
- Pay close attention to YAML indentation and use the correct
apiVersionand schema for the resource you define.