
Kubernetes manifest basics
Kubernetes objects are typically defined using YAML files. Most manifests include four top-level fields:apiVersion, kind, metadata, and spec. The exact structure of spec depends on the resource kind (for example, a Pod’s spec looks different from a Deployment’s spec).
Some resources may omit
spec or include additional required fields. For core objects like Pods use apiVersion: v1; other resources often use apps/v1.
Always use consistent spaces (not tabs) for indentation in YAML. Incorrect indentation can change structure or make the file invalid.
Example: Single-container Pod manifest
This minimal Pod manifest creates a Pod namedmyapp-pod that runs an nginx container:
metadata.nameis the unique name for the Pod (myapp-pod).metadata.labelsis a key/value map used for grouping and selecting objects later (for example withkubectl get pods -l app=myapp).spec.containersis a list because a Pod can include multiple containers. Each container item must include at leastnameandimage.
Common YAML indentation mistake
Incorrect indentation can change the document structure. In the example belowlabels is incorrectly indented under name, which is invalid:
name and labels must be siblings under metadata (same indentation level):
Create and inspect the Pod
Save the manifest to a file, for examplepod-definition.yaml, and apply it with:
- List Pods:
- View detailed Pod information:
- Get the Pod manifest as stored in the API server (YAML output):
Summary
- Kubernetes manifests are YAML files that commonly include the four top-level fields:
apiVersion,kind,metadata, andspec. - For a Pod,
specmust include acontainersarray with at leastnameandimagefor each container. - YAML is indentation-sensitive — use consistent spacing and verify sibling relationships (e.g.,
nameandlabelsundermetadata). - Use
kubectl create -fto create the Pod andkubectl get/kubectl describe/kubectl get -o yamlto inspect it.