kubectl apply. Using a manifest gives you versionable, declarative control over the Pod’s desired state (recommended for reproducible deployments) versus the ephemeral kubectl run imperative command.
This page covers:
- the minimal Pod manifest structure
- a working example that runs the
nginximage - how to apply the file and inspect the Pod with
kubectl - a trimmed
kubectl describeexample and common fields
Pod manifest basics
Create a file calledpod.yaml (for example, vim pod.yaml). A minimal Pod manifest has four top-level fields:
Notes:
labelsis a mapping insidemetadataand is useful for selectors and organization (e.g.,app: nginx).containersis a YAML sequence. Each list item is a container object; the hyphen denotes a sequence item.- Container
nameis the container identifier inside the Pod and can differ from the image name. - For images from non-Docker Hub registries, specify the full path:
registry.example.com/myrepo/myimage:tag.
Use consistent indentation (two spaces recommended). Avoid tabs — inconsistent indentation breaks YAML parsing.
Minimal Pod manifest example
Createpod.yaml with the contents below to run an nginx container:
Example terminal session
A typical session creating the Pod and checking status looks like this:Inspecting the Pod
To view detailed runtime information, use:kubectl describe output (some fields omitted for brevity). This output helps you debug scheduling, image pulls, container state, events, and mounted volumes.
Tips and next steps
- Use manifests to store desired state in source control and to recreate environments consistently.
- When you need multiple replicas and rolling updates, transition from a Pod manifest to a Deployment manifest.
- Add probes (
livenessProbe,readinessProbe), resource requests/limits, and environment variables to the container spec as your application requirements grow.