Skip to content
thesarfo

Concept

Kubernetes: Pods

The smallest deployable unit in Kubernetes, what it is, and the kubectl commands to create and inspect one.

views 0

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: v1
kind: Pod
metadata:
name: nginx-pod
labels:
run: nginx-pod
spec:
containers:
- name: nginx-pod
image: nginx:1.22.1
ports:
- containerPort: 80

To create the Pod:

Terminal window
kubectl create -f def-pod.yaml

To generate a YAML or JSON template without running the Pod:

Terminal window
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.json

To manage and inspect the Pod:

Terminal window
kubectl apply -f nginx-pod.yaml
kubectl get pods
kubectl get pod nginx-pod -o yaml
kubectl get pod nginx-pod -o json
kubectl describe pod nginx-pod
kubectl delete pod nginx-pod

YAML files are sensitive to indentation, use 2 spaces per indent and avoid tabs.