A Pod is the smallest and most basic unit in Kubernetes. It represents one instance of an application and can contain one or more containers that:
- Run on the same node.
- Share the same IP address and network namespace.
- Can access shared storage (volumes).
Pods are temporary and don’t recover on their own if they fail. That’s why they are typically managed by controllers like Deployments, ReplicaSets, or Jobs, which provide replication, healing, and updates. The Pod definition is included inside the controller’s spec as a Pod Template.
A basic standalone Pod can be created declaratively using a YAML manifest or imperatively using commands.
Example YAML manifest:
apiVersion: v1kind: Podmetadata: name: nginx-pod labels: run: nginx-podspec: containers: - name: nginx-pod image: nginx:1.22.1 ports: - containerPort: 80To create the Pod:
kubectl create -f def-pod.yamlTo generate a YAML or JSON template without running the Pod:
kubectl run nginx-pod --image=nginx:1.22.1 --port=80 \--dry-run=client -o yaml > nginx-pod.yaml
kubectl run nginx-pod --image=nginx:1.22.1 --port=80 \--dry-run=client -o json > nginx-pod.jsonTo manage and inspect the Pod:
kubectl apply -f nginx-pod.yamlkubectl get podskubectl get pod nginx-pod -o yamlkubectl get pod nginx-pod -o jsonkubectl describe pod nginx-podkubectl delete pod nginx-podYAML files are sensitive to indentation, use 2 spaces per indent and avoid tabs.