
apiVersion, kind, metadata, and spec. These are the root-level properties required by most Kubernetes objects.
Details for each field:
apiVersion: Specifies which API version to use. Pods usev1in the core API group. Other resources may useapps/v1,networking.k8s.io/v1, etc.kind: The resource type you want to create (for example,Pod,Deployment,Service).metadata: A map with identifying fields such asname,namespace,labels, andannotations.spec: The specification for the resource. For Pods,specmust include acontainerslist where each container has at least anameand animage.
YAML is indentation-sensitive. Keys at the same logical level must have the same indentation. Under
metadata, keys like name and labels should be siblings with the same indent; keys under labels must be further indented. Do not add arbitrary fields under metadata—only keys that Kubernetes expects (like name, namespace, labels, annotations, etc.).spec.containers is a list. Each item in that list is a map describing a container (minimum: name and image). Below is a minimal, correct Pod manifest. Save it as pod-definition.yml.
apiVersion: v1andkind: Podtell Kubernetes you’re creating a Pod using the corev1API.- Under
metadata,nameis the Pod’s identifier andlabelsis a map used for selection and grouping. spec.containersis a list allowing multiple containers in a single Pod; this example describes one container namednginx-containerusing thenginximage.
kubectl apply -f pod-definition.yml to create or update a resource declaratively.
To list Pods in the current namespace:
Pods are ephemeral. If a Pod is deleted or fails, it won’t be automatically recreated unless it is managed by a controller (for example, a Deployment or ReplicaSet). For production workloads, prefer using Deployments to manage Pod lifecycle and scaling.
- Kubernetes manifests typically include
apiVersion,kind,metadata, andspec. - Under
metadata, use only supported fields such asname,namespace,labels, andannotations. specis resource-specific; for Pods it contains acontainerslist where each container has at leastnameandimage.- Use
kubectl create -f <file>orkubectl apply -f <file>to create resources,kubectl get podsto list Pods, andkubectl describe pod <name>for detailed information.